Using classes

Pages: 12
This may help.
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;


class student
{
private: 
         //attributes for the student class
         string fName;
         string lName;
         string id;
         string schoolName;
        
public:
       //declaring variables
       student()
       {
                fName = "";
                lName = "";
                id = -1;
                               
                cout << "Student constructor running\n" << endl;
       }
       //calling function to get students first name
       string getfName()
       {             
           return fName;      
       }
       //calling function to get students last name
        string getlName()
       {             
           return lName;      
       }         
       //call function to get id number
       string getID()
       {          
           return id;              
       }
   
       //calling function to get school name
       string getschoolName()
       {                 
           return schoolName;
       }  
           
       void setfName(string s)
       {
            fName = s;            
       }
       
       void setlName(string s)
       {
            lName = s;            
       }              
       
       void setID(string s)
       {
            id = s;              
       }
       //setting the name for the school for the student and returing it
       void setschoolName(string s)
       {		
          if(s == "d")
             schoolName = "Devry";
          else if(s =="n")
             schoolName = "Nursery";
          else if(s == "t")
             schoolName = "Tonys";
          else if(s == "m")
             schoolName = "Miss Anns";         
            
     }
         
};

class DeVryStu : public student
{
private:
      string campus;
      string program;

public: 
     DeVryStu()
     {
        cout << "Devry student constructor is running.\n";       
               
        campus = "-";
        program = "-";
     }
	    DeVryStu(string newid,string newfname,string newlname ,string newschoolName,string newcampus ,string newprogram)
     {
        cout << "Devry student constructor is running.\n";       
		student::setID(newid);
		student::setfName(newfname);
		student::setlName(newlname);
		student::setschoolName(newschoolName);
        campus = newcampus;
        program = newprogram;
     }
     //getting what campus the student goes to
     string getDCampus()
     {
            return campus;
     }
     //getting what school program the student is in
     string getDProgram()
     {
            return program;
     }
     
     void setDCampus(string s)
     {
          campus = s;
     }
     
     void setDProgram(string s)
     {
          program = s;

     }   
            
};

class NurseryStu: public student
{
private:
      string campus;
      string program;

public: 
     NurseryStu()
     {
        cout << "Nursery student constructor is running.\n";       
               
        campus = "-";
        program = "-";
     }
	    NurseryStu(string newid,string newfname,string newlname ,string newschoolName,string newcampus ,string newprogram)
     {
        cout << "Nursery student constructor is running.\n";       
		student::setID(newid);
		student::setfName(newfname);
		student::setlName(newlname);
		student::setschoolName(newschoolName);
        campus = newcampus;
        program = newprogram;
     }
     //getting what campus the student goes to
     string getNCampus()
     {
            return campus;
     }
     //getting what school program the student is in
     string getNProgram()
     {
            return program;
     }
     
     void setNCampus(string s)
     {
          campus = s;
     }
     
     void setNProgram(string s)
     {
          program = s;

     }   
            
};

class TonyStu: public student
{
private:
      string campus;
      string program;

public: 
     TonyStu()
     {
        cout << "Tonys student constructor is running.\n";       
               
        campus = "-";
        program = "-";
     }
	    TonyStu(string newid,string newfname,string newlname ,string newschoolName,string newcampus ,string newprogram)
     {
        cout << "Tonys student constructor is running.\n";       
		student::setID(newid);
		student::setfName(newfname);
		student::setlName(newlname);
		student::setschoolName(newschoolName);
        campus = newcampus;
        program = newprogram;
     }
     //getting what campus the student goes to
     string getTCampus()
     {
            return campus;
     }
     //getting what school program the student is in
     string getTProgram()
     {
            return program;
     }
     
     void setTCampus(string s)
     {
          campus = s;
     }
     
     void setTProgram(string s)
     {
          program = s;

     }   
            
};
class MissAnnStu: public student
{
private:
      string campus;
      string program;

public: 
     MissAnnStu()
     {
        cout << "Miss Ann student constructor is running.\n";       
               
        campus = "-";
        program = "-";
     }
	    MissAnnStu(string newid,string newfname,string newlname ,string newschoolName,string newcampus ,string newprogram)
     {
        cout << "MissAnn student constructor is running.\n";       
		student::setID(newid);
		student::setfName(newfname);
		student::setlName(newlname);
		student::setschoolName(newschoolName);
        campus = newcampus;
        program = newprogram;
     }
     //getting what campus the student goes to
     string getMCampus()
     {
            return campus;
     }
     //getting what school program the student is in
     string getMProgram()
     {
            return program;
     }
     
     void setMCampus(string s)
     {
          campus = s;
     }
     
     void setMProgram(string s)
     {
          program = s;

     }   
            
};




void stuff()
{
     

string fName = "-";
string lName = "-";
string id = "-";
string schoolName = "-";
string campus = "-";
string program = "-";

cout << "Please enter the ID number : ";
cin >> id;


//asking for first name and stroing it in fName
cout << "Please enter the first name of the student:  ";
cin >> fName;

//asking for last name and storingit in lName
cout << "Please enter the last name of the student:  ";
cin >> lName;


//asking what school the student attends
cout << "Enter what school the student attends: (d)evry\n"
     << "(n)ursery, (t)ony's Judo school, (m)iss Ann's Dance School:  ";
cin >> schoolName;

     if ( schoolName=="d")
	 {
		 cin.ignore();
		 cout<<"Enter Devry campus: ";
			getline(cin,campus);
		
		 cout<<"Enter Devry program: ";
			getline(cin,program);
		
		 DeVryStu Dstudent(id,fName,lName,schoolName,campus,program);
		cout << "Student id: " << Dstudent.getID() << endl
			 << "Student name: " << Dstudent.getfName() << " " 
			 << Dstudent.getlName() << endl
		     << "Student goes to :" << Dstudent.getschoolName()<< endl
			 <<"Student  Campus : "<<Dstudent.getDCampus()<<endl
			 <<"Student Program : " <<Dstudent.getDProgram()<<endl;
	 }
	  else if(schoolName =="n")
	  {  
		   cin.ignore();
		 cout<<"Enter Nursery campus: ";
			getline(cin,campus);
		
		 cout<<"Enter Nursery  program: ";
			getline(cin,program);
		
		 NurseryStu Nstudent(id,fName,lName,schoolName,campus,program);
		cout << "Student id: " << Nstudent.getID() << endl
			 << "Student name: " << Nstudent.getfName() << " " 
			 << Nstudent.getlName() << endl
		     << "Student goes to :" << Nstudent.getschoolName()<< endl
			 <<"Student  Campus : "<<Nstudent.getNCampus()<<endl
			 <<"Student Program : " <<Nstudent.getNProgram()<<endl;
	 }
Last edited on
code continued
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
    else if(schoolName == "t")
	{

		 cin.ignore();
		 cout<<"Enter Tony's judo school campus: ";
			getline(cin,campus);
		
		 cout<<"Enter Tony's judo school program: ";
			getline(cin,program);
		
		 TonyStu Tstudent(id,fName,lName,schoolName,campus,program);
		cout << "Student id: " << Tstudent.getID() << endl
			 << "Student name: " << Tstudent.getfName() << " " 
			 << Tstudent.getlName() << endl
		     << "Student goes to :" << Tstudent.getschoolName()<< endl
			 <<"Student  Campus : "<<Tstudent.getTCampus()<<endl
			 <<"Student Program : " <<Tstudent.getTProgram()<<endl;

	  }
    else if(schoolName == "m")
	{
       cin.ignore();
		 cout<<"Enter Miss Ann's Dance School campus: ";
			getline(cin,campus);
		
		 cout<<"Enter Miss Ann's Dance School program: ";
			getline(cin,program);
		
		MissAnnStu Mstudent(id,fName,lName,schoolName,campus,program);
		cout << "Student id: " << Mstudent.getID() << endl
			 << "Student name: " <<Mstudent.getfName() << " " 
			 << Mstudent.getlName() << endl
		     << "Student goes to :" << Mstudent.getschoolName()<< endl
			 <<"Student  Campus : "<<Mstudent.getMCampus()<<endl
			 <<"Student Program : " <<Mstudent.getMProgram()<<endl;
	}
	else
	{

		cout<<"INVALID"<<endl;

	}
}


int main()
{
    
stuff();
    
system("PAUSE");
return EXIT_SUCCESS;

}
Thanks, I am starting to understand classes a little more now. So in each class I need to set new variables and keep them separate for each class. Could I make each class a different method and call them within int main?
Yes.
Topic archived. No new replies allowed.
Pages: 12