-
Notifications
You must be signed in to change notification settings - Fork 0
/
structures.cpp
83 lines (69 loc) · 1.92 KB
/
structures.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
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
using namespace std;
void preview(struct Student student);
struct Student
{
string fName = "";
string lName = "";
int age = -1;
int roll;
void listOfSubj();
string getDetails();
string subjects[3];
string getFullName(string f, string l)
{
return f + " " + l;
};
} student, student1, student2;
string Student::getDetails()
{
string age_stringified = to_string(age);
string roll_stringified = to_string(roll);
return fName + "-" +
lName + "-" +
roll_stringified + "-" +
age_stringified;
}
void Student::listOfSubj()
{
for (int i = 0; i < 3; i++)
{
cout << subjects[i] << " :: ";
}
}
int main()
{
// struct Student student1;
// struct Student student2;
student1.fName = "Aryan";
student1.lName = "Jain";
student1.age = 24;
student1.roll = 161;
// student1.subjects->append("Math");
// student1.subjects->append("English");
// student1.subjects->append("Science");
student2.fName = "John";
student2.lName = "Hopkins";
student2.age = 51;
student2.roll = 162;
student2.subjects[0] = "Hindi";
student2.subjects[1] = "Biology";
student2.subjects[2] = "Social Science";
// std::cout << "Student: " << student.fName << "-" << student.roll << endl;
// std::cout << "Student: " << student1.fName << "-" << student1.roll << endl;
// std::cout << "Student: " << student2.fName << "-" << student2.roll << endl;
preview(student2);
// preview(student);
return 1;
}
void preview(struct Student student)
{
cout << "Student Data: " << endl;
cout << "Name: " << student.getFullName(student.fName + "-", student.lName + "-") << endl;
cout << "Age: " << student.age << endl;
cout << "Roll: " << student.roll << endl;
cout << "Details: " << student.getDetails() << endl;
cout << "Subjects: ";
student.listOfSubj();
return;
}