1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include<iostream>
#include<string>
using namespace std;
class Module
{
public:
void setObj(string, string, string, int);//mutator
void getObj(string&, string&, string&, int&)const;// accessor
void print() const;
Module();//default constructor
Module(string , string ,string, int);
private:
string moduleName;
string moduleCode;
string lecturer;
int nrStudent;
};
void print(Module);
void fill (Module);
int main()
{
Module moduleOne;
print(moduleOne);
fill(moduleOne);
print(moduleOne);
return 0;
}
void print(Module modOne)
{
cout<<"Module Information "<<endl;
modOne.print();
cout<< endl;
}
void fill(Module modOne)
{
string one, two, three;
int four;
cout<< "Enter Module name"<<endl;
getline(cin, one, '\n');
cout<< "Enter Module code"<<endl;
getline(cin, two, '\n');
cout<< "Enter Lecturer"<<endl;
getline(cin, three, '\n');;
cout<< "Enter Student Number"<<endl;
cin>> four;
modOne.setObj(one, two, three, four);
cout<<endl;
}
Module::Module()
{
moduleName;
moduleCode;
lecturer;
nrStudent;
}
Module::Module(string one, string two, string three, int four)
{
setObj(one, two, three, four);
}
void Module::setObj(string one, string two, string three, int four)
{
moduleName=one;
moduleCode=two;
lecturer=three;
nrStudent=four;
}
void Module::getObj(string &one, string &two, string &three, int &four) const
{
one =moduleName;
two = moduleCode;
three=lecturer;
four=nrStudent;
}
void Module::print()const
{
cout<<"Module name is :";
cout<<moduleName<<endl;
cout<<"Module code :";
cout<<moduleCode<<endl;
cout<<"Lecturer :";
cout<<lecturer<<endl;
cout<<"Number of students :";
cout<<nrStudent<<endl;
}
|