Advertisement
Imran_Mohammed

Class_In_cpp

Jan 7th, 2023
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class student{
  5.  
  6.     public:
  7.     string name;
  8.     int id;
  9.     int age;
  10.     double cg;
  11.  
  12.     void printInfo(){
  13.         cout << "Name : " << name << endl;
  14.         cout << "ID : " << id << endl;
  15.         cout << "Age : " << age << endl;
  16.         cout << "CG : " << cg << endl;
  17.         cout << endl;
  18.     }
  19.  
  20.     student(string s , int i , int age , double d){
  21.         name = s;
  22.         id = i;
  23.         this->age = age;
  24.         cg = d;
  25.     }
  26.  
  27.     student(string s , int i , int age){
  28.         name = s;
  29.         id = i;
  30.         this->age = age;
  31.     }
  32.  
  33.     //Destructor called in reverse order
  34.     ~student(){
  35.         printInfo();
  36.     }
  37.  
  38. };
  39.  
  40. int main(){
  41.  
  42.     student s1("Imran Mohammed"  , 20701024 , 22 , 3.60);
  43.     s1.printInfo();
  44.  
  45.     student s2("sanvi"  , 20701087 , 22);
  46.     s2.printInfo();
  47.  
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement