sidrs

OOP Ass 2 - Student Database

Aug 2nd, 2024 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Student{
  7. private:
  8.     string name, grade, div, birthDate, bloodGroup, address, roll, license, phone;
  9.     string email;
  10.     static string college;
  11. public:
  12.     Student(){
  13.         name = "NAME SURNAME";
  14.         grade = "CLASS";
  15.         div = "DIVISION";
  16.         birthDate = "01/01/2000";
  17.         bloodGroup = "BLOOD GROUP";
  18.         address = "ADDRESS";
  19.         roll = "00";
  20.         phone = "0000000000";
  21.         email = "[email protected]";
  22.         license = "0LX000000";
  23.  
  24.     }
  25.  
  26.     Student(const Student &obj){
  27.         name = obj.name;   
  28.         grade = obj.grade; 
  29.         div = obj.div; 
  30.         birthDate = obj.birthDate; 
  31.         bloodGroup = obj.bloodGroup;   
  32.         address = obj.address; 
  33.         roll = obj.roll;   
  34.         phone = obj.phone; 
  35.         license = obj.license; 
  36.     }
  37.  
  38.     void initData(){
  39.         cout << "\n ----- ENTER STUDENT DETAILS -----" << endl;
  40.         cout << "Enter Name: "; getline(cin, name);
  41.         cout << "Enter Class: "; getline(cin, grade);
  42.         cout << "Enter Division: "; getline(cin, div);
  43.         cout << "Enter Date of Birth: "; getline(cin, birthDate);
  44.         cout << "Enter Blood Group: "; getline(cin, bloodGroup);
  45.         cout << "Enter Address: "; getline(cin, address);
  46.         cout << "Enter Roll No.: "; getline(cin, roll);
  47.  
  48.         cout << "Enter Phone No.: "; getline(cin, phone);
  49.         // Exception Handling for Phone Number (Checking if Phone Number exceeds 10 digits)
  50.  
  51.  
  52.         cout << "Enter Email: "; getline(cin, email);
  53.         // Vewy Basic Exception Handling for email (Checking for the '@' character)
  54.         int flag = 0;
  55.         try {
  56.             for (int i = 0; i < email.size(); i++){
  57.                 if (email[i] == '@') {
  58.                     flag = 1;
  59.                     break;
  60.                 }
  61.             }
  62.  
  63.             if (flag == 0) {
  64.                 throw(email);
  65.             }
  66.                
  67.         } catch (string email1) {
  68.             cout << "ERROR! Please enter a Valid Email!" << endl;
  69.             cout << "Enter a Valid Email: ";
  70.             getline(cin, email);
  71.         }
  72.         cout << "Enter Driving License No.: "; getline(cin, license);
  73.         cout << endl;
  74.     }
  75.     void displayData(){
  76.         cout << "\n STUDENT DETAILS FOR: " << name << endl;
  77.         cout << "--------------------------" << endl;
  78.         cout << "Name: " << name << endl;
  79.         cout << "Class: " << grade << endl;
  80.         cout << "Division: " << div << endl;
  81.         cout << "Roll No.: " << roll << endl;
  82.         cout << "Date of Birth: " << birthDate << endl;
  83.         cout << "Blood Group: " << bloodGroup << endl;
  84.         cout << "Address: " << address << endl;
  85.         cout << "Phone No.: " << phone << endl;
  86.         cout << "Email : " << email << endl;
  87.         cout << "Driving License No.: " << license << endl;
  88.         cout << "Institute: " << college << endl;
  89.         cout << endl;
  90.     }
  91.  
  92.     static void getCollege(){
  93.         cout << college << endl;
  94.     }
  95.  
  96. };
  97.  
  98. string Student::college = "International Institute of Information Technology";
  99.  
  100. int main(){
  101.     Student S1;
  102.     S1.initData();
  103.     S1.displayData();
  104.     Student::getCollege();
  105.  
  106.  
  107.     return 0;
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment