Here's a simple C++ program for a school management system:
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
int rollNumber;
int age;
string className;
public:
void inputDetails() {
cout << "Enter student name: ";
cin.ignore();
getline(cin, name);
cout << "Enter roll number: ";
cin >> rollNumber;
cout << "Enter age: ";
cin >> age;
cout << "Enter class name: ";
cin.ignore();
getline(cin, className);
}
void displayDetails() {
cout << "\nStudent Details\n";
cout << "Name: " << name << endl;
cout << "Roll Number: " << rollNumber << endl;
cout << "Age: " << age << endl;
cout << "Class Name: " << className << endl;
}
};
class Teacher {
private:
string name;
string subject;
int age;
public:
void inputDetails() {
cout << "Enter teacher name: ";
cin.ignore();
getline(cin, name);
cout << "Enter subject: ";
getline(cin, subject);
cout << "Enter age: ";
cin >> age;
}
void displayDetails() {
cout << "\nTeacher Details\n";
cout << "Name: " << name << endl;
cout << "Subject: " << subject << endl;
cout << "Age: " << age << endl;
}
};
class School {
private:
string schoolName;
string address;
Student students[10];
Teacher teachers[10];
int numberOfStudents;
int numberOfTeachers;
public:
void inputSchoolDetails() {
cout << "Enter school name: ";
cin.ignore();
getline(cin, schoolName);
cout << "Enter school address: ";
getline(cin, address);
}
void addStudent() {
students[numberOfStudents].inputDetails();
numberOfStudents++;
}
void addTeacher() {
teachers[numberOfTeachers].inputDetails();
numberOfTeachers++;
}
void displayStudentDetails() {
for (int i = 0; i < numberOfStudents; i++) {
students[i].displayDetails();
}
}
void displayTeacherDetails() {
for (int i = 0; i < numberOfTeachers; i++) {
teachers[i].displayDetails();
}
}
void displaySchoolDetails() {
cout << "\nSchool Details\n";
cout << "Name: " << schoolName << endl;
cout << "Address: " << address << endl;
}
};
int main() {
School school;
int choice;
school.numberOfStudents = 0;
school.numberOfTeachers = 0;
school.inputSchoolDetails();
while (true) {
cout << "\nSchool Management System\n";
cout << "1. Add student\n";
cout << "2. Add teacher\n";
cout << "3. Display student details\n";
cout << "4. Display teacher details\n";
cout << "5. Display school details\n";
cout << "6. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
school.addStudent();
break;
case 2:
school.addTeacher();
break;
case 3:
school.displayStudentDetails();
break;
case 4:
school.displayTeacherDetails();
break;
case 5:
school.displaySchoolDetails();
break;
case 6:
return 0;
default:
cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}
```
*Example Output:*
```
Enter school name: ABC School
Enter school address: 123 Main St
School Management System
1. Add student
2. Add teacher
3. Display student details
4. Display teacher details
5. Display school details
6. Exit
Enter your choice: 1
Enter student name: John Doe
Enter roll number: 1
Enter age: 12
Enter class name: 7th
School Management System
1. Add student
2. Add teacher
3. Display student details
4. Display teacher details
5. Display school details
6. Exit
Enter your choice: 3
Student Details
Name: John Doe
Roll Number: 1
Age: 12
Class Name: 7th
School Management System
1. Add student
2. Add teacher
3. Display student details
4. Display teacher details
5. Display school details
6. Exit
Enter your choice: 5
School Details
Name: ABC School
Address: 123 Main St
No comments:
Post a Comment