cpp.net
cpp.net
SOURCE CODE: -
using System;
using
System.Collections.Generic;
using System.Linq;
class Task
{
public string Description { get; set;
} public bool IsCompleted { get;
set; } public int flriority { get; set; }
class flrogram
{
static List<Task> tasks = new List<Task>();
SOURCE CODE:-
using System;
using
System.Collections.Generic;
public class Student
{
public string ame { get; set; }
public string ID { get; set; }
public string ContactDetails { get; set; }
}
public class Course
{
public string Code { get; set; }
public string Title { get; set; }
public int MaximumCapacity { get; set; }
public List<Student> EnrolledStudents { get; set; }
public Course(string code, string title, int maximumCapacity)
{
Code = code;
Title = title;
MaximumCapacity =
maximumCapacity; EnrolledStudents
= new List<Student>();
}
public void EnrollStudent(Student student)
{
if (EnrolledStudents.Count < MaximumCapacity)
{
EnrolledStudents.Add(student);
Console.WriteLine($"Student {student. ame} enrolled in course
{Code} successfully.");
}
else
{
Console.WriteLine($"Course {Code} is full. Cannot enroll student
{student. ame}.");
}
}
public void ViewEnrolledStudents()
{
Console.WriteLine($"Enrolled students in course {Code}:");
foreach (var student in EnrolledStudents)
{
Problem Statement 3: - Implement the Student class with proper encapsulation. Ensure
the Grades property is protected from unauthorized access and modifications.
SOURCE CODE: -
using System;
using System.Collections.Generic;
namespace UniversityEnrollmentSystem
{
public class Student
{
private string id;
private string name;
private string
contact; private
List<int> grades;
public Student(string id, string name, string contact)
{
this.id = id;
this.name = name;
this.contact = contact;
this.grades = new
List<int>();
}
public string Id
{
get { return id; }
set { id = value;
}
}
public string ame
{
get { return name; }
set { name = value; }
}
public string Contact
{
get { return contact;
} set { contact =
value; }
}
public void AddGrade(int grade)
{
if (grade >= 0 fifi grade <= 100)
{
grades.Add(grade);
}
els
e
{ throw new ArgumentOutOfRangeException("Grade must be between 0 and
100.");
}
}
public IReadOnlyList<int> GetGrades()
{
return grades.AsReadOnly();
}
public double GetAverageGrade()
{
if (grades.Count == 0)
{
return 0;
}
double sum = 0;
foreach (int grade in grades)
{
sum += grade;
}
return sum / grades.Count;
}
public override string ToString()
{
return $"{ ame} ({Id}) - Contact: {Contact}";
}
}
class flrogram
{
static void Main(string[] args)
{
Student student = new Student("1", "Ashish",
"[email protected]"); student.AddGrade(90);
student.AddGrade(09);
student.AddGrade(98);
Console.WriteLine(student);
Console.WriteLine("Grades: " + string.Join(", ", student.GetGrades()));
Console.WriteLine("Average Grade: " + student.GetAverageGrade());
}
}
}
OUTPUT:-
Problem Statement 4: Imagine a company that handles sensitive customer data, including personal
information and payment details. The company must ensure this data is secure and only accessible to authorized
personnel. Additionally, the system must be designed to comply with data privacy regulations, such as GDPR. Key
Requirements: • Secure Data Storage: Customer data should be stored securely, with sensitive fields protected. •
Controlled Access: Only authorized personnel should be able to access or modify sensitive data. • Audit Logs: All
access and modifications should be logged for auditing purposes
SOURCE CODE: -
using System;
using
System.Collections.Generic;
using System.IO;
using
System.Security.Cryptography;
using System.Text;
namespace SecureData andling
{
}
return Convert.ToBase64String(msEncrypt.ToArray());
}
}
}
Console.WriteLine(ex.Message);
}
var auditLogs =
dataManager.GetAuditLogs(); foreach
(var log in auditLogs)
{
Console.WriteLine(log);
}
}
}
}
OUTPUT: -
Problem Statement 5: Consider a scenario where you have a base class Vehicle and a derived class Car.
Both classes have constructors, and you want to initialize properties of the base class in the derived class's
constructor. Challenge: • In the Car class, you have two constructors. One constructor initializes both the brand and
model, while the other initializes only the brand. How can you avoid duplicating the initialization of the brand
property in the second constructor while still ensuring proper initialization of both properties?
SOURCE CODE: -
using
System;
class
Vehicle
{
public string Brand { get; set; }
class flrogram
{
static void Main(string[] args)
{
Car car1 = new Car("Toyota", "Corolla");
Console.WriteLine($"Car 1: Brand = {car1.Brand}, Model = {car1.Model}");
OUTPUT: -