Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <iomanip>
- using namespace std;
- struct date
- {
- int day, mon, yr;
- };
- struct student
- {
- string id;
- string name;
- double totcre, grapo, cgpa;
- date dob;
- };
- double calcgpa (double gp, double cd);
- struct date getdate ();
- struct student getstu ();
- void printstu (student a);
- int main()
- {
- int n, choice = 3, i;
- string temp;
- cout << "Number of Students: ";
- getline (cin, temp);
- stringstream (temp) >> n;
- struct student stu[n];
- while (choice != 0)
- {
- cout << "Enter 1 to Write information" << endl << "Enter 2 to Read information" << endl << "Enter 0 to Exit" << endl;
- getline (cin, temp);
- stringstream (temp) >> choice;
- if (choice == 1)
- {
- cout << "Enter the entry number to write: ";
- getline (cin, temp);
- stringstream (temp) >> i;
- if (i > 0 && i <= n)
- stu[i-1] = getstu();
- //for (i = 0; i < n; i++)
- //stu[i] = getstu();
- else
- cout << "Error! Invalid Entry Number";
- }
- else if (choice == 2)
- {
- cout << "Enter the entry number to read: ";
- getline (cin, temp);
- stringstream (temp) >> i;
- if (i > 0 && i <= n)
- printstu (stu[i-1]);
- //for (i = 0; i < n; i++)
- //printstu(stu[i]);
- else
- cout << "Error! Invalid Entry Number";
- }
- else if (choice == 0)
- break;
- }
- return 0;
- }
- double calcgpa (double gp, double cd)
- {
- return (gp/cd);
- }
- date getdate ()
- {
- date d;
- string temp;
- cout << "Enter the Birthday (DD MM YYYY): ";
- getline (cin, temp);
- stringstream (temp) >> d.day;
- getline (cin, temp);
- stringstream (temp) >> d.mon;
- getline (cin, temp);
- stringstream (temp) >> d.yr;
- return d;
- }
- student getstu ()
- {
- student a;
- string temp;
- cout << "Enter Student ID: ";
- getline (cin, a.id);
- cout << "Enter Student's Name: ";
- getline (cin, a.name);
- a.dob = getdate ();
- cout << "Enter Total Credits Completed: ";
- getline (cin, temp);
- stringstream (temp) >> a.totcre;
- cout << "Enter Grade Point: ";
- getline (cin, temp);
- stringstream (temp) >> a.grapo;
- a.cgpa = calcgpa (a.grapo, a.totcre);
- cout << "Information of " << a.name << " has been stored successfully" << endl << endl;
- return a;
- }
- void printstu (student a)
- {
- cout << left << setw(30) << "ID: " << a.id << endl;
- cout << left << setw(30) << "Name: " << a.name << endl;
- cout << left << setw(30) << "Date of Birth: " << a.dob.day << " - " << a.dob.mon << " - " << a.dob.yr << endl;
- cout << left << setw(30) << "Total Credits Completed: " << a.totcre << endl;
- cout << left << setw(30) << "Grade Point: " << a.grapo << endl;
- cout << left << setw(30) << "CGPA: " << left << setw(2) << a.cgpa << endl << endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement