-
Notifications
You must be signed in to change notification settings - Fork 1
/
listOfStudents.txt
157 lines (135 loc) · 2.5 KB
/
listOfStudents.txt
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
153
154
155
156
157
// ConsoleApplication1.cpp : Defines the entry point for the console application.
// mareksip
#include "stdafx.h"
#include <conio.h>
#include <stdlib.h>
typedef
struct TStudent {
char fname[50];
char sname[50];
int birthyear;
TStudent *next;
} TStudent ;
TStudent *first=NULL;
void GetStudentInfo(TStudent *newstudent)
{
//Complete this function
printf("Enter students first name: ");
scanf_s("%s",newstudent->fname,50);
printf("Enter students surname: ");
scanf_s("%s",newstudent->sname,50); // newstudent->fname is same as (*newstudent).fname
printf("Enter year of birth: ");
scanf_s("%d",&newstudent->birthyear);
}
void AddStudent()
{
TStudent *student;
student=(TStudent *) malloc(sizeof(TStudent));
GetStudentInfo(student);
student->next=first;
first=student;
}
void PrintStudentInfo(TStudent *student)
{
printf("Student %s %s, born %d\n",student->fname,student->sname,student->birthyear);
}
void ListStudents()
{
int num = 1;
printf("\n");
printf("*** Start of list ***\n");
printf("\n");
TStudent *student;
//First version
student=first;
while (student!=NULL)
{
printf("%2d. ",num);
PrintStudentInfo(student);
num++;
student=student->next;
}
//End of first version
//for (student=first;student!=NULL;student=student->next) {
// PrintStudentInfo(student);
//}
printf("\n");
printf("*** End of list ***\n");
printf("\n");
}
void PrintMenu()
{
printf("\n");
printf("Menu\n");
printf("==========\n");
printf("1. Add student\n");
printf("2. List students\n");
printf("3. Delete student\n");
printf("9. Exit\n");
printf("\n");
}
void DeleteStudent()
{
int toDelete;
int pom = 1;
ListStudents();
printf("Which student you want to delete?\n ");
scanf_s("%d",&toDelete);
TStudent *student;
student = first;
if(toDelete == 1)
{
TStudent *a=first;
first=first->next;
free(a);
}
else
{
while (student!=NULL)
{
if(toDelete - 1 == pom)
{
TStudent *a;
a = student->next;
student->next=student->next->next;
free(a);
}
pom++;
student=student->next;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0;
char input;
AddStudent();
do
{
PrintMenu();
input = _getch();
if(input == '1')
{
AddStudent();
}
if(input == '2')
{
ListStudents();
}
if(input == '3')
{
DeleteStudent();
}
if(input != '1' || input != '2' || input != '3' || input != '9')
{
// printf("Menu only contains following options:\n");
}
if(input == '9')
{
break;
}
}
while(a<1);
//_getch(); //// knihovna #include <conio.h>
return 0;
}