0% found this document useful (0 votes)
3 views8 pages

Sda Code

The document contains a C++ implementation of a university management system with classes for Department, Teacher, Course, Student, Enrollment, Result, Library, and University. Each class includes methods for inputting and displaying details, allowing for the management of university entities and their relationships. The main function drives the system by creating a University object and adding various components, followed by displaying the collected data.

Uploaded by

urwazahra01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Sda Code

The document contains a C++ implementation of a university management system with classes for Department, Teacher, Course, Student, Enrollment, Result, Library, and University. Each class includes methods for inputting and displaying details, allowing for the management of university entities and their relationships. The main function drives the system by creating a University object and adding various components, followed by displaying the collected data.

Uploaded by

urwazahra01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

#include <iostream>

#include <string>
using namespace std;

// Department Class
class Department {
public:
int deptID;
string deptName;

// Function to input department details


void input() {
cout << "Enter Department ID: ";
cin >> deptID;
cout << "Enter Department Name: ";
cin.ignore(); // To handle any leftover newlines in the input buffer
getline(cin, deptName); // To allow spaces in department names
}

// Function to display department details


void display() {
cout << "Dept ID: " << deptID << ", Name: " << deptName << endl;
}
};

// Teacher Class
class Teacher {
public:
int teacherID;
string name;
Department* dept;

// Function to input teacher details


void input(Department* d) {
cout << "Enter Teacher ID: ";
cin >> teacherID;
cout << "Enter Teacher Name: ";
cin.ignore(); // To clear the input buffer before getting the name
getline(cin, name); // To allow spaces in teacher name
dept = d; // Assign department pointer to the department passed
}

// Function to display teacher details


void display() {
cout << "Teacher ID: " << teacherID << ", Name: " << name << ", Dept: " <<
dept->deptName << endl;
}
};

// Course Class
class Course {
public:
int courseID;
string courseName;
Teacher* teacher;
Department* dept;

// Function to input course details


void input(Teacher* t, Department* d) {
cout << "Enter Course ID: ";
cin >> courseID;
cout << "Enter Course Name: ";
cin.ignore(); // To handle spaces in course name
getline(cin, courseName);
teacher = t; // Assign teacher pointer to the teacher passed
dept = d; // Assign department pointer to the department passed
}

// Function to display course details


void display() {
cout << "Course ID: " << courseID << ", Name: " << courseName << ", Teacher: " <<
teacher->name << endl;
}
};

// Student Class
class Student {
public:
int studentID;
string name;
Department* dept;

// Function to input student details


void input(Department* d) {
cout << "Enter Student ID: ";
cin >> studentID;
cout << "Enter Student Name: ";
cin.ignore(); // To handle spaces in student name
getline(cin, name);
dept = d; // Assign department pointer to the department passed
}

// Function to display student details


void display() {
cout << "Student ID: " << studentID << ", Name: " << name << ", Dept: " <<
dept->deptName << endl;
}
};

// Enrollment Class
class Enrollment {
public:
Student* student;
Course* course;

// Function to input enrollment details


void input(Student* s, Course* c) {
student = s; // Assign student pointer to the student passed
course = c; // Assign course pointer to the course passed
}

// Function to display enrollment details


void display() {
cout << student->name << " enrolled in " << course->courseName << endl;
}
};

// Result Class
class Result {
public:
Student* student;
Course* course;
float marks;

// Function to input result details


void input(Student* s, Course* c) {
student = s; // Assign student pointer to the student passed
course = c; // Assign course pointer to the course passed
cout << "Enter Marks for " << student->name << " in " << course->courseName << ": ";
cin >> marks;
}
// Function to display result details
void display() {
cout << student->name << " in " << course->courseName << " scored: " << marks << endl;
}
};

// Library Class
class Library {
public:
int bookID;
string bookTitle;
bool isAvailable;

// Function to input library book details


void input() {
cout << "Enter Book ID: ";
cin >> bookID;
cout << "Enter Book Title: ";
cin.ignore(); // To handle spaces in book title
getline(cin, bookTitle);
isAvailable = true; // Initially, books are available
}

// Function to display library book details


void display() {
cout << "Book ID: " << bookID << ", Title: " << bookTitle << ", Available: " << (isAvailable ?
"Yes" : "No") << endl;
}

// Function to borrow a book


void borrowBook() {
if (isAvailable) {
isAvailable = false;
cout << "You borrowed the book: " << bookTitle << endl;
} else {
cout << "Book is not available." << endl;
}
}

// Function to return a book


void returnBook() {
isAvailable = true;
cout << "You returned the book: " << bookTitle << endl;
}
};

// University Class
class University {
public:
string universityName;
Department departments[10];
Teacher teachers[10];
Student students[10];
Course courses[10];
Enrollment enrollments[10];
Result results[10];
Library library[10];
int deptCount, teacherCount, studentCount, courseCount, enrollmentCount, resultCount,
bookCount;

// Constructor to initialize counters


University() {
deptCount = teacherCount = studentCount = courseCount = enrollmentCount =
resultCount = bookCount = 0;
}

// Function to input university name


void inputUniversity() {
cout << "Enter University Name: ";
cin.ignore();
getline(cin, universityName);
}

// Function to add department


void addDepartment() {
cout << "Adding Department:\n";
departments[deptCount].input(); // Direct input without input operator
deptCount++;
}

// Function to add teacher


void addTeacher() {
cout << "Adding Teacher:\n";
if (deptCount > 0) {
Teacher newTeacher; // Creating a new Teacher object
cout << "Enter Teacher details:\n";
newTeacher.input(&departments[deptCount - 1]); // Pass the last added department
teachers[teacherCount] = newTeacher; // Store the teacher in the array
teacherCount++;
} else {
cout << "No department available.\n";
}
}

// Function to add course


void addCourse() {
cout << "Adding Course:\n";
if (teacherCount > 0 && deptCount > 0) {
Course newCourse; // Creating a new Course object
cout << "Enter Course details:\n";
newCourse.input(&teachers[teacherCount - 1], &departments[deptCount - 1]); // Pass
the last added teacher and department
courses[courseCount] = newCourse; // Store the course in the array
courseCount++;
} else {
cout << "No teacher or department available.\n";
}
}

// Function to add student


void addStudent() {
cout << "Adding Student:\n";
if (deptCount > 0) {
Student newStudent; // Creating a new Student object
cout << "Enter Student details:\n";
newStudent.input(&departments[deptCount - 1]); // Pass the last added department
students[studentCount] = newStudent; // Store the student in the array
studentCount++;
} else {
cout << "No department available.\n";
}
}

// Function to add enrollment


void addEnrollment() {
cout << "Adding Enrollment:\n";
if (studentCount > 0 && courseCount > 0) {
Enrollment newEnrollment; // Creating a new Enrollment object
cout << "Enter Enrollment details:\n";
newEnrollment.input(&students[studentCount - 1], &courses[courseCount - 1]); // Pass
the last added student and course
enrollments[enrollmentCount] = newEnrollment; // Store the enrollment in the array
enrollmentCount++;
} else {
cout << "No student or course available.\n";
}
}

// Function to add result


void addResult() {
cout << "Adding Result:\n";
if (studentCount > 0 && courseCount > 0) {
results[resultCount].input(&students[studentCount - 1], &courses[courseCount - 1]); //
Pass the last added student and course
resultCount++;
} else {
cout << "No student or course available.\n";
}
}

// Function to add book


void addBook() {
cout << "Adding Book to Library:\n";
library[bookCount].input(); // Direct input without input operator
bookCount++;
}

// Function to display university details


void displayUniversity() {
cout << "University: " << universityName << endl;
cout << "\nDepartments:\n";
for (int i = 0; i < deptCount; i++) departments[i].display();
cout << "\nTeachers:\n";
for (int i = 0; i < teacherCount; i++) teachers[i].display();
cout << "\nStudents:\n";
for (int i = 0; i < studentCount; i++) students[i].display();
cout << "\nCourses:\n";
for (int i = 0; i < courseCount; i++) courses[i].display();
cout << "\nEnrollments:\n";
for (int i = 0; i < enrollmentCount; i++) enrollments[i].display();
cout << "\nResults:\n";
for (int i = 0; i < resultCount; i++) results[i].display();
cout << "\nLibrary Books:\n";
for (int i = 0; i < bookCount; i++) library[i].display();
}
};
// Main function to drive the University System
int main() {
University uni;
uni.inputUniversity();

// Add departments, teachers, courses, students, etc.


uni.addDepartment();
uni.addTeacher();
uni.addCourse();
uni.addStudent();
uni.addEnrollment();
uni.addResult();
uni.addBook();

// Display all the data


uni.displayUniversity();
return 0;
}

You might also like