-
Notifications
You must be signed in to change notification settings - Fork 0
/
displaystudent.cpp
152 lines (151 loc) · 3.27 KB
/
displaystudent.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
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
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
//------------Variable Declaration---------//
struct marks
{
string subject;
float s_marks;
marks *m_next;
};
struct student
{
string name;
student *next;
marks *s_next;
};
student *s_head = NULL;
marks *head = NULL;
//------------Function Prototypes---------//
int menu();
void Input();
void addRecord(string name, string subject, float m);
student *getLastRecord(student *s_head);
void display();
void print();
//---------------Main Body---------------//
main()
{
int option = menu();
while (true)
{
if (option == 1)
{
Input();
cout << endl;
getch();
system("cls");
}
if (option == 2)
{
print();
cout << endl;
getch();
system("cls");
}
if(option == 3)
{
break;
}
option = menu();
getch();
system("cls");
}
}
//---------Functions Definition---------//
int menu()
{
int op;
cout << endl;
cout << endl;
cout << "\t Menu" << endl;
cout<<"_____________________________________"<<endl;
cout << endl;
cout << "\t1. Add Record" << endl;
cout << "\t2. view Record" << endl;
cout << "\t3. Exit" << endl;
cout << endl;
cout<<"____________________________________"<<endl;
cout << "Select any option:";
cin >> op;
return op;
}
void Input()
{
string name, subject;
float mark;
cout << endl;
cout << "Enter name of student: ";
cin >> name;
cout << "Enter Subject: ";
cin >> subject;
cout << "Enter marks: ";
cin >> mark;
cout << endl;
addRecord(name, subject, mark);
}
void addRecord(string name, string subject, float mark)
{
while (s_head != NULL)
{
if (s_head->name == name)
{
while (head != NULL)
{
marks *m_record = new marks;
m_record->subject = subject;
m_record->s_marks = mark;
m_record->m_next = NULL;
}
}
}
student *s_record = new student;
s_record->name = name;
s_record->s_next = NULL;
s_record->next = NULL;
marks *my_record = new marks;
my_record->subject = subject;
my_record->s_marks = mark;
my_record->m_next = NULL;
if (s_head == NULL)
{
s_head = s_record;
}
else
{
student *temp = getLastRecord(s_head);
temp->next = s_record;
}
}
student *getLastRecord(student *s_head)
{
while (s_head != NULL)
{
s_head = s_head->next;
}
return s_head;
}
void display(student *temp)
{
cout << temp->name;
cout << endl;
while (temp->s_next != NULL)
{
while (head != NULL)
{
cout << "Subject: " << temp->s_next->subject << "\t\t";
cout << "Marks: " << temp->s_next->s_marks;
head = head->m_next;
}
}
}
void print()
{
student *myRecord = s_head;
while (myRecord->next != NULL)
{
display(myRecord);
myRecord = myRecord->next;
}
}