-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path52_using_a_class.cpp
More file actions
101 lines (79 loc) · 2.03 KB
/
52_using_a_class.cpp
File metadata and controls
101 lines (79 loc) · 2.03 KB
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
/*Goal: Practice using a class*/
#include<iostream>
using namespace std;
class Student
{
string name;
int id;
int gradDate;
public:
void setName(string nameIn);
void setId(int idIn);
void setGradDate(int dateIn);
string getName();
int getId();
int getGradDate();
void print();
};
void Student::setName(string nameIn)
{
name = nameIn;
}
void Student::setId(int idIn)
{
id = idIn;
}
void Student::setGradDate(int gradDateIn)
{
gradDate = gradDateIn;
}
void Student::print()
{
cout<<name<<" "<<id<<" "<<gradDate;
}
string Student::getName()
{
return name;
}
int Student::getId()
{
return id;
}
int Student::getGradDate()
{
return gradDate;
}
int main()
{
int integer1;
float float1;
Student student1;
// integer1 = 4; //assign a value to integer1
// float1 = 4.333; //assign a value to float1
student1.setName("Catherine Gamboa"); //assign a value to the student name
student1.setId(54345); //assign a value to the student id number
student1.setGradDate(2017); //assign a value to the student grad date
//Let's print the values of our variables
// cout<<"integer1 = "<<integer1<<"\n";
// cout<<"float1 = "<<float1<<"\n\n";
//There are two ways we can print the values of our class:
//The first is to call the print function we created.
cout<<"Using the Student::print function\n";
cout<<"Student1 = ";
student1.print();
cout<<"\n\n";
//The second is to access each member of the class using the get functions
cout<<"Using the student access functions\n";
cout<<"Student1 name = "<<student1.getName()<<"\n";
cout<<"Student1 ID = "<<student1.getId()<<"\n";
cout<<"Student1 Grad Date = "<<student1.getGradDate()<<"\n";
return 0;
}
/*
Using the Student::print function
Student1 = Catherine Gamboa 54345 2017
Using the student access functions
Student1 name = Catherine Gamboa
Student1 ID = 54345
Student1 Grad Date = 2017
*/