Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Student
- {
- private:
- int ID;
- string name;
- double grade;
- public:
- Student()
- {
- setID(0);
- setName(" ");
- setGrade(0);
- }
- void setID(int x)
- {
- if(x<0)
- cout<<"Invalid value, please enter a positive ID!";
- else
- ID=x;
- }
- void setGrade(double x)
- {
- while(x<0)
- {
- cout<<"Invalid value, please enter a positive grade!";
- }
- grade=x;
- }
- void setName(string a)
- {
- if(a.size()>0)
- name=a;
- else
- cout<<"Invalid name";
- }
- int getID()
- {
- return ID;
- }
- string getName()
- {
- return name;
- }
- double getGrade()
- {
- return grade;
- }
- void print()
- {
- cout<<"the ID is: "<< ID<<endl;
- cout<<"the name is "<<name<<endl;
- cout<<"the grade is "<<grade<<endl;
- }
- void readinfo()
- {
- int id;
- string name=" ";
- double g;
- cout<<"enter ID :";
- cin>>id;
- setID(id);
- cout<<"Enter name: ";
- cin>>name;
- setName(name);
- cout<<"Enter grade: ";
- cin>>g;
- setGrade(g);
- }
- };
- int main()
- {
- Student st[10];
- for(int i=0; i<10;i++)
- {
- st[i].readinfo();
- st[i].print();
- }
- }
Add Comment
Please, Sign In to add comment