Skip to content

Commit a1cc766

Browse files
Students Data Program
Data of students added using struct
1 parent 08770c0 commit a1cc766

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

displaystudent.cpp

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#include <iostream>
2+
#include <conio.h>
3+
#include <windows.h>
4+
using namespace std;
5+
//------------Variable Declaration---------//
6+
struct marks
7+
{
8+
string subject;
9+
float s_marks;
10+
marks *m_next;
11+
};
12+
struct student
13+
{
14+
string name;
15+
student *next;
16+
marks *s_next;
17+
};
18+
student *s_head = NULL;
19+
marks *head = NULL;
20+
//------------Function Prototypes---------//
21+
int menu();
22+
void Input();
23+
void addRecord(string name, string subject, float m);
24+
student *getLastRecord(student *s_head);
25+
void display();
26+
void print();
27+
//---------------Main Body---------------//
28+
main()
29+
{
30+
int option = menu();
31+
while (true)
32+
{
33+
if (option == 1)
34+
{
35+
Input();
36+
cout << endl;
37+
getch();
38+
system("cls");
39+
}
40+
if (option == 2)
41+
{
42+
print();
43+
cout << endl;
44+
getch();
45+
system("cls");
46+
}
47+
if(option == 3)
48+
{
49+
break;
50+
}
51+
option = menu();
52+
getch();
53+
system("cls");
54+
}
55+
}
56+
//---------Functions Definition---------//
57+
int menu()
58+
{
59+
60+
int op;
61+
cout << endl;
62+
cout << endl;
63+
cout << "\t Menu" << endl;
64+
cout<<"_____________________________________"<<endl;
65+
cout << endl;
66+
cout << "\t1. Add Record" << endl;
67+
cout << "\t2. view Record" << endl;
68+
cout << "\t3. Exit" << endl;
69+
cout << endl;
70+
cout<<"____________________________________"<<endl;
71+
cout << "Select any option:";
72+
cin >> op;
73+
return op;
74+
}
75+
void Input()
76+
{
77+
string name, subject;
78+
float mark;
79+
cout << endl;
80+
cout << "Enter name of student: ";
81+
cin >> name;
82+
cout << "Enter Subject: ";
83+
cin >> subject;
84+
cout << "Enter marks: ";
85+
cin >> mark;
86+
cout << endl;
87+
addRecord(name, subject, mark);
88+
}
89+
void addRecord(string name, string subject, float mark)
90+
{
91+
while (s_head != NULL)
92+
{
93+
if (s_head->name == name)
94+
{
95+
while (head != NULL)
96+
{
97+
marks *m_record = new marks;
98+
m_record->subject = subject;
99+
m_record->s_marks = mark;
100+
m_record->m_next = NULL;
101+
}
102+
}
103+
}
104+
student *s_record = new student;
105+
s_record->name = name;
106+
s_record->s_next = NULL;
107+
s_record->next = NULL;
108+
marks *my_record = new marks;
109+
my_record->subject = subject;
110+
my_record->s_marks = mark;
111+
my_record->m_next = NULL;
112+
if (s_head == NULL)
113+
{
114+
s_head = s_record;
115+
}
116+
else
117+
{
118+
student *temp = getLastRecord(s_head);
119+
temp->next = s_record;
120+
}
121+
}
122+
student *getLastRecord(student *s_head)
123+
{
124+
while (s_head != NULL)
125+
{
126+
s_head = s_head->next;
127+
}
128+
return s_head;
129+
}
130+
void display(student *temp)
131+
{
132+
cout << temp->name;
133+
cout << endl;
134+
while (temp->s_next != NULL)
135+
{
136+
while (head != NULL)
137+
{
138+
cout << "Subject: " << temp->s_next->subject << "\t\t";
139+
cout << "Marks: " << temp->s_next->s_marks;
140+
head = head->m_next;
141+
}
142+
}
143+
}
144+
void print()
145+
{
146+
student *myRecord = s_head;
147+
while (myRecord->next != NULL)
148+
{
149+
display(myRecord);
150+
myRecord = myRecord->next;
151+
}
152+
}

displaystudent.exe

52.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)