#include <iostream>
#include <string>
using namespace std;
#define MAX 1000
class Student
{
private:
string ID;
string Firstname;
string Lastname;
bool Gender;
double Math;
double Physics;
double English;
double Avg;
public:
void read();
string getFullname();
string getID();
double getAvg();
void printIDandFullname();
};
class Classroom
{
private:
Student student[MAX];
int n;
public:
string getsID;
string getsFullname;
void readStudents();
void printStudents();
void addaStudent();
void findIDStudent();
};
int main()
{
Classroom KTMT2015;
KTMT2015.readStudents();
KTMT2015.printStudents();
KTMT2015.addaStudent();
KTMT2015.printStudents();
KTMT2015.findIDStudent();
system("pause");
return 0;
}
void Student::read()
{
cin.ignore();
cout << "ID: ";
getline(cin, ID);
cout << "Firstname: ";
getline(cin, Firstname);
cout << "Last name: ";
getline(cin, Lastname);
cout << "Gener (Male - 1; Female - 0): ";
cin >> Gender;
cout << "Math:";
cin >> Math;
cout << "Physic: ";
cin >>Physics;
cout << "English: ";
cin >> English;
Avg = getAvg();
}
string Student::getFullname()
{
return Firstname + " " + Lastname;
}
string Student::getID()
{
return ID;
}
double Student::getAvg()
{
return (Math + Physics + English) / 3;
}
void Student::printIDandFullname()
{
cout << ID << "\t" << getFullname();
}
void Classroom::readStudents()
{
cout << "Number of student: ";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "Student " << i + 1<< ": " << endl;
student[i].read();
}
}
void Classroom::printStudents()
{
cout << "Number\tID\tFullname" << endl;
for (int i = 0; i < n; i++)
{
cout << i + 1 << "\t" << student[i].getID() << "\t" << student[i].getFullname() << endl;
}
}
void Classroom::addaStudent()
{
cout << "Enter information of new student: " << endl;
n = n + 1;
student[n].read();
}
void Classroom::findIDStudent()
{
string IDfind;
cout << "Enter ID: ";
cin >> IDfind;
for (int i = 0; i < n; i++)
{
if (IDfind.compare(student[i].getID()) == 0)
student[i].printIDandFullname();
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.