Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TODO: Phone Number Fetching
- #include <iostream>
- #include <string>
- using namespace std;
- class Student {
- string name, address, irn, grade, dob;
- int roll;
- char *blood, *div;
- static string university;
- public:
- long long phone;
- friend class Contact;
- friend class Database;
- Student(){
- name = "NULL";
- address = "NULL";
- irn = "NULL";
- grade = "NULL";
- roll = 00;
- phone = 0000000000;
- blood = new char[1];
- div = new char[1];
- }
- void setData(){
- cin.ignore();
- blood = new char[4];
- div = new char[4];
- cout << "\nENTER DETAILS ----- ----- ----- ----- ----- -----";
- cout << "\n\nEnter Name: "; getline(cin, name);
- cout << "\nEnter Class (Year and Branch): "; getline(cin, grade);
- cout << "\nEnter Roll: "; cin >> roll;
- cout << "\nEnter Division: "; cin >> div;
- cout << "\nEnter Date of Birth (DD/MM/YYYY): "; cin >> dob;
- cout << "\nEnter Blood Group (A+, A-, B+, B-, AB+, AB-, O+, O-): "; cin >> blood;
- cout << "\nEnter IRN: "; cin >> irn;
- cin.ignore();
- cout << "\nEnter Address: "; getline(cin, address);
- }
- ~Student() {
- delete[] blood;
- }
- };
- class Contact {
- long long phone;
- public:
- void setPhone() {
- try {
- cout << "\nEnter Phone No.: "; cin >> phone;
- if ((phone < 1000000000) or (phone > 9999999999)) {
- cout << "\nERROR! Invalid Phone Number";
- throw (phone);
- }
- } catch (long long phone) {
- cout << "\nEnter a Valid Phone No.: "; cin >> phone;
- }
- }
- };
- class Database {
- public:
- void fetchData(Student &obj){
- cout << "\n\n----- ----- ----- ----- ----- ----- ----- -----";
- cout << "\n\nDETAILS FOR STUDENT: " << obj.name;
- cout << "\nName: " << obj.name;
- cout << "\nClass: " << obj.grade;
- cout << "\nRoll No.: " << obj.roll;
- cout << "\nBlood Group: " << obj.blood;
- cout << "\nPhone No.: " << obj.phone;
- cout << "\nIRN: " << obj.irn;
- cout << "\nAddress: " << obj.address;
- cout << "\nCollege Name: " << Student::university;
- cout << "\n\n----- ----- ----- ----- ----- ----- ----- -----";
- }
- static void fetchCollege() {
- cout << "\nCollege Name: " << Student::university;
- }
- inline int fetchRoll(Student &obj) {
- return obj.roll;
- }
- };
- string Student::university = "I2IT, Pune";
- int main() {
- int n;
- cout << "\nEnter the number of students: "; cin >> n;
- Student students[n];
- Contact contacts[n];
- Database db;
- for (int i = 0; i < n; i++){
- students[i].setData();
- contacts[i].setPhone();
- }
- cout << "\n ----- ----- ----- ----- ----- ----- ----- -----";
- while (true) {
- int choice;
- cout << "\n\n----- MENU ----- ----- ----- ----- ----- -----";
- cout << "\n1: Show All Data\n2: Search by Roll No\n3: Exit";
- cout << "\nEnter choice number: ";
- cin >> choice;
- if (choice == 1) {
- cout << "\n----- SHOWING ALL DATA ----- ----- ----- ----- -----";
- for (int i = 0; i < n; i++) {
- db.fetchData(students[i]);
- }
- }
- else if (choice == 2) {
- while (true) {
- int ROLL, breaker;
- int flag = 0;
- cout << "\nEnter the Roll No. you want to look up (Enter -1 to Exit): "; cin >> ROLL;
- if (ROLL == -1) break;
- else {
- for (int i = 0; i < n; i++){
- if (ROLL == db.fetchRoll(students[i])) {
- db.fetchData(students[i]);
- flag = 1;
- break;
- }
- }
- if (!flag) {
- cout << "\nERROR! Record Not Found";
- cout << "\nDo you want to Continue? (Enter 1 for Yes, 0 for No): "; cin >> breaker;
- if (breaker != 1) {
- break;
- }
- }
- }
- }
- }
- else if (choice == 3) {
- cout << "\nTERMINATING PROGRAM\n";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment