fork download
  1. //week-2(problem 1.2)
  2.  
  3. #include<iostream>
  4. using namespace std;
  5. class student
  6. {
  7. int id;
  8. string name;
  9. float cgpa;
  10. public:
  11. void set_values(int a,string d,float c)
  12. {
  13. id=a;
  14. name=d;
  15. cgpa=c;
  16.  
  17.  
  18. }
  19. void Display()
  20. {
  21. cout<<"student id :"<<id<<endl;
  22. cout<<"Name :"<<name<<endl;
  23. cout<<"Cgpa :"<<cgpa<<endl;
  24. cout<<"---------------------"<<endl;
  25.  
  26. }
  27.  
  28. };
  29.  
  30.  
  31. int main()
  32. {
  33. student s1,s2;
  34. int x;
  35. string y;
  36. float z;
  37. cout<<"Enter your id :";
  38.  
  39. cin>>x;
  40. cout<<"Enter your name :";
  41. cin.ignore();
  42. getline(cin,y);
  43. cout<<"Enter your cgpa :";
  44. cin>>z;
  45. s1.set_values(x,y,z);
  46.  
  47.  
  48. cout<<"\nEnter your friend's id :";
  49. cin>>x;
  50. cout<<"Enter your friend's name :";
  51. cin.ignore();
  52. getline(cin,y);
  53. cout<<"Enter your friend's cgpa :";
  54. cin>>z;
  55. s2.set_values(x,y,z);
  56.  
  57.  
  58. s1.Display();
  59.  
  60. s2.Display();
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter your id :Enter your name :Enter your cgpa :
Enter your friend's id :Enter your friend's name :Enter your friend's cgpa :student id :1395122240
Name       :
Cgpa       :7.51797e-42
---------------------
student id :1395122240
Name       :
Cgpa       :7.51797e-42
---------------------