daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Student
  6. {
  7. private:
  8.     int ID;
  9.     string name;
  10.     double grade;
  11. public:
  12.     Student()
  13. {
  14.     setID(0);
  15.     setName(" ");
  16.     setGrade(0);
  17. }
  18. void setID(int x)
  19. {
  20.     if(x<0)
  21.         cout<<"Invalid value, please enter a positive ID!";
  22.     else
  23.         ID=x;
  24. }
  25. void setGrade(double x)
  26. {
  27.     while(x<0)
  28.     {
  29.         cout<<"Invalid value, please enter a positive grade!";
  30.     }
  31.         grade=x;
  32. }
  33. void setName(string a)
  34. {
  35.     if(a.size()>0)
  36.         name=a;
  37.     else
  38.         cout<<"Invalid name";
  39. }
  40. int getID()
  41. {
  42.     return ID;
  43. }
  44. string getName()
  45. {
  46.     return name;
  47. }
  48. double getGrade()
  49. {
  50.     return grade;
  51. }
  52. void print()
  53. {
  54.     cout<<"the ID is: "<< ID<<endl;
  55.     cout<<"the name is "<<name<<endl;
  56.     cout<<"the grade is "<<grade<<endl;
  57. }
  58.  
  59. void readinfo()
  60. {
  61.     int id;
  62.     string name=" ";
  63.     double g;
  64.     cout<<"enter ID :";
  65.     cin>>id;
  66.     setID(id);
  67.     cout<<"Enter name: ";
  68.     cin>>name;
  69.     setName(name);
  70.  
  71.     cout<<"Enter grade: ";
  72.     cin>>g;
  73.     setGrade(g);
  74. }
  75. };
  76. int main()
  77. {
  78.     Student st[10];
  79.     for(int i=0; i<10;i++)
  80.     {
  81.         st[i].readinfo();
  82.         st[i].print();
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top