OOD LAB
OOD LAB
OOD LAB
Star-uml :
Code :
#include "bits-stdc++.h"
using namespace std;
class Course
{
string name;
vector<int> faculties;
string id;
int credits;
// Map<ScholarID, List of Dates>
map<string, vector<int>> attendance;
public:
Course() {}
Course(const string &courseName, const string &courseId, int courseCredits)
: name(courseName), id(courseId), credits(courseCredits) {}
class Faculty
{
public:
int id;
string name;
string department;
Faculty() {}
Faculty(int id, string name, string department) : id(id), name(name), department(department) {}
class Transaction
{
time_t timestamp;
double amount;
string from;
string to;
string reason;
public:
Transaction(string from, string to, double amount, string reason) : from(from),
to(to), amount(amount), reason(reason),
timestamp(chrono::system_clock::to_time_t(chrono::system_clock::now())) {}
public:
Registrar(double initialBalance) : balance(initialBalance) {}
class Event {
public:
int id;
string name;
double budget;
string coordinator;
bool isBudgetApproved;
Event() {}
Event(int id, string name, string coordinator, double budget) : name(name),
coordinator(coordinator), budget(budget), isBudgetApproved(false),
id(id) {}
class Student
{
int id;
public:
string name;
string address;
Student() {}
Student(int id, string name, string address) : name(name), address(address), id(id) {}
};
int main()
{
bool run = true;
int choice;
map<string, Course> courses;
map<int, Faculty> faculties;
map<int, Student> students;
map<int, Event> events;
Registrar registrar(10000000000);
while (run)
{
cout << "Welcome to the Menu\n"
"1. Courses\n"
"2. Events\n"
"3. Faculty\n"
"4. Registrar\n"
"5. Student\n"
"6. Dean \n"
"7. Exit\n"
"Choose an option: ";
cin >> choice;
if (choice == 1) {
cout << "Sub menu Options for Courses:\n1. Add Course\n2. Remove Course\n3. Display
Faculties\n4. Exit\nChoose an option: ";
cin >> choice;
if (choice == 1) {
cout << "Adding a course..." << endl;
string courseName, courseId;
int courseCredits;
cout << "Enter Course Name: ";
cin.ignore();
getline(cin, courseName);
cout << "Enter Course ID: ";
cin >> courseId;
cout << "Enter Course Credits: ";
cin >> courseCredits;
cout << "Do you want to add more faculties? (1 for Yes, 0 for No): ";
cin >> addMoreFaculties;
}
courses[newCourse.getId()] = newCourse;
} else if (choice == 2) {
cout << "Removing a course..." << endl;
cout << "Course ID\tCourse Name" << endl;
for (const auto &course : courses) {
cout << course.first << "\t" << course.second.getName() << endl;
}
string courseIdToRemove;
cout << "Enter Course ID to Remove: ";
cin >> courseIdToRemove;
auto it = courses.find(courseIdToRemove);
if (it != courses.end()) {
courses.erase(it);
cout << "Course with ID " << courseIdToRemove << " removed successfully." << endl;
} else {
cout << "Course with ID " << courseIdToRemove << " not found." << endl;
}
} else if (choice == 3) {
cout << "Displaying faculties for selected course..." << endl;
cout << "Select a Course:" << endl;
for (const auto &course : courses) {
cout << course.first << "\t" << course.second.getName() << endl;
}
cout << "Enter choice: ";
string courseChoice;
cin >> courseChoice;
auto it = courses.find(courseChoice);
if (it != courses.end()) {
vector<int> courseFaculties = courses[courseChoice].getFaculties();
for (int facultyID: courseFaculties) {
cout << facultyID << "." << faculties[facultyID-1].name;
}
} else {
cout << "Invalid course choice." << endl;
}
} else if (choice == 4) {
continue;
} else {
cout << "Invalid submenu choice." << endl;
}
} else if (choice == 2) {
cout << "Sub menu Options for Cultural Events\n1. Add Event\n2. Remove Event\n3. Exit\nChoose
an option: ";
cin >> choice;
if (choice == 1)
{
cout << "Creating a new event..." << endl;
int eventId = (int)events.size();
string eventName, coordinatorName;
double eventBudget;
auto it = events.find(removeId);
if (it != events.end())
{
events.erase(it);
cout << "Event with ID " << removeId << " removed successfully." << endl;
}
else
{
cout << "Event with ID " << removeId << " not found." << endl;
}
}
else if (choice == 3)
{
continue;
}
else
{
cout << "Invalid choice. Please try again." << endl;
}
} else if (choice == 3) {
cout << "Sub menu Options for Faculty:\n1. Add Faculty\n2. Remove Faculty\n3. Exit\nChoose an
option: ";
cin >> choice;
if (choice == 1) {
cout << "Adding a new faculty member..." << endl;
int facultyId = (int)faculties.size();
string facultyName, facultyDepartment;
cout << "Enter Faculty Name: ";
cin.ignore();
getline(cin, facultyName);
cout << "Enter Faculty Department: ";
getline(cin, facultyDepartment);
auto it = faculties.find(removeId);
if (it != faculties.end()) {
faculties.erase(it);
} else {
cout << "Faculty with ID " << removeId << " not found." << endl;
}
} else {
cout << "Invalid choice. Please try again." << endl;
}
} else if (choice == 4) {
cout << "Registrar Options:\n1. Show All Transactions\n2. Make Payment\n3. Get Balance\n4.
Exit\nChoose an option: ";
cin >> choice;
if (choice == 1) {
cout << "All Transactions:" << endl;
vector<Transaction> allTransactions = registrar.getAllTransactions();
for ( auto& transaction : allTransactions) {
cout << "From: " << transaction.getFrom() << ", To: " << transaction.getTo()
<< ", Amount: ₹" << transaction.getAmount() << ", Reason: " << transaction.getReason() <<
endl;
}
} else if (choice == 2) {
string from, to, reason;
double amount;
cout << "Enter payer's name: ";
cin >> from;
cout << "Enter payee's name: ";
cin >> to;
cout << "Enter payment amount: $";
cin >> amount;
cin.ignore(); // Ignore newline character
cout << "Enter payment reason: ";
getline(cin, reason);
if (choice == 1) {
cout << "Adding a new Student..." << endl;
int studentId = (int)students.size();
string studentName, studentAddress;
cout << "Enter Student Name: ";
cin.ignore();
getline(cin, studentName);
cout << "Enter Student Address: ";
getline(cin, studentAddress);
auto it = students.find(removeId);
if (it != students.end()) {
students.erase(it);
} else {
cout << "Student with ID " << removeId << " not found." << endl;
}
} else if (choice == 3) {
student.second.name = newStudentName;
student.second.address = newStudentAddress;
cout << "Student details updated successfully." << endl;
break; // Stop searching after updating the details
}
}
} else {
cout << "Invalid choice. Please try again." << endl;
}
} else if (choice == 6) {
cout << "You chose Dean." << endl;
} else if (choice == 7) {
cout << "Exiting the program..." << endl;
run = false;
} else {
cout << "Invalid choice. Please try again." << endl;
}