forked from ksvkabra/learn-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.cpp
More file actions
65 lines (57 loc) · 1.84 KB
/
student.cpp
File metadata and controls
65 lines (57 loc) · 1.84 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
#include <iostream>
#include <string.h>
using namespace std;
class student
{
//private by default
char name[20];
int roll_no;
int maths;
int physics;
int chemistry;
int average;
public:
//constructor
student(char *name, int roll_no, int maths, int physics, int chemistry)
{
strcpy(this->name, name);
this->roll_no = roll_no;
this->maths = maths;
this->physics = physics;
this->chemistry = chemistry;
}
int set()
{
cin >> roll_no >> maths >> physics >> chemistry;
cin >> name;
}
int get()
{
cout << name << endl
<< roll_no << endl
<< maths << endl
<< physics << endl
<< chemistry << endl
<< average;
}
int calcAverage()
{
average = (maths + physics + chemistry) / 3;
}
};
int main()
{
student ayushi = student("ayushi", 123, 100, 100, 100);
// ayushi.set();
ayushi.calcAverage();
ayushi.get();
}
// constructor is an initializer, it initializes the properties of a class when an object is created, if we do not create a construtor then there exists a default construtor with empty body and 0 arguments;
// properties are simply the object properties and methods are the functionalities an object can perform
// there are three access method for class properties and methods
// 1. private -> the properties and methods only accessible by the member functions(methods)
// 2. protected -> accessible by the member function and inherited classes
// 3 public -> accessible by the object .
//static -> when all the object have the same value for a variable that means the variable belongs to the class not the objects individually
// destructor when a class object scope ends it is destroyed and free from memory
// this pointer -> it is default pointer which points to the members of the class and represents the object instance which call the members.