-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectExample3.cpp
71 lines (61 loc) · 1.17 KB
/
ObjectExample3.cpp
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
#include <iostream>
#include <string.h>
using namespace std;
class Marks {
private:
int rno;
float perc;
public:
//constructor
Marks()
{
rno = 0;
perc = 0.0f;
}
//input roll numbers and percentage
void readMarks(void)
{
cout << "Enter roll number: ";
cin >> rno;
cout << "Enter percentage: ";
cin >> perc;
}
//print roll number and percentage
void printMarks(void)
{
cout << "Roll No.: " << rno << endl;
cout << "Percentage: " << perc << "%" << endl;
}
};
class Student {
private:
//object to Marks class
Marks objM;
char name[30];
public:
//input student details
void readStudent(void)
{
//Input name
cout << "Enter name: ";
cin.getline(name, 30);
//input Marks
objM.readMarks();
}
//print student details
void printStudent(void)
{
//print name
cout << "Name: " << name << endl;
//print marks
objM.printMarks();
}
};
//main code
int main()
{
//create object to student class
Student std;
std.readStudent();
std.printStudent();
ret