-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChallenge.cpp
More file actions
157 lines (156 loc) · 3.61 KB
/
Challenge.cpp
File metadata and controls
157 lines (156 loc) · 3.61 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;
// Prototypes
struct studentType;
struct marksType;
void loadDispayGride();
void gotoxy(int x, int y);
void takeInput();
void storeRecord(string name, string subject, float marks); // store the user record in the linked-list
studentType *getLastRecordStu(studentType *temp);
marksType *getLastRecordMark(marksType *temp);
void printSingleRecordStu(studentType *onerecord);
void printSingleRecordMark(marksType *onerecord);
void displayAllRecords();
// Data structure pre defined
int const xAxix = 25;
int const yAxix = 92;
char gride[xAxix][yAxix];
// Data structure user defined
struct studentType
{
string name; // name
studentType *stu_next;
// marksType *stuMrk_next;
};
struct marksType
{
string subject; // subject
float subjMarks; // marks
marksType *mrk_next;
};
studentType *stuHead = NULL;
marksType *mrkHead = NULL;
// Main function
int main()
{
loadDispayGride();
while (true)
{
takeInput();
displayAllRecords();
}
}
void loadDispayGride()
{
// load gride
string record;
fstream load;
load.open("Gride.txt", ios::in);
for (int x = 0; x < xAxix; x++)
{
getline(load, record);
for (int y = 0; y < yAxix; y++)
{
gride[x][y] = record[y];
}
}
load.close();
// display girde
system("cls");
for (int x = 0; x < xAxix; x++)
{
for (int y = 0; y < yAxix; y++)
{
cout << gride[x][y];
}
cout << endl;
}
}
void gotoxy(int x, int y)
{
COORD coordinates;
coordinates.X = x;
coordinates.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordinates);
}
void takeInput()
{
string stuName, stuSubject;
float stuMarks;
gotoxy(17, 21);
cin >> stuName;
gotoxy(17, 22);
cin >> stuSubject;
gotoxy(17, 23);
cin >> stuMarks;
storeRecord(stuName, stuSubject, stuMarks);
}
void storeRecord(string name, string subject, float marks)
{
studentType *recordStudent = new studentType;
marksType *recordMarks = new marksType;
recordStudent->name = name;
recordStudent->stu_next = NULL;
recordMarks->subject = subject;
recordMarks->subjMarks = marks;
recordMarks->mrk_next = NULL;
if (stuHead == NULL && mrkHead == NULL)
{
stuHead = recordStudent;
mrkHead = recordMarks;
}
else
{
studentType *obj1 = getLastRecordStu(stuHead);
obj1->stu_next = recordStudent;
marksType *obj2 = getLastRecordMark(mrkHead);
obj2->mrk_next = recordMarks;
}
}
studentType *getLastRecordStu(studentType *temp)
{
while (temp->stu_next != NULL)
{
temp = temp->stu_next;
}
return temp;
}
marksType *getLastRecordMark(marksType *temp)
{
while (temp->mrk_next != NULL)
{
temp = temp->mrk_next;
}
return temp;
}
void printSingleRecordStu(studentType *onerecord)
{
gotoxy(1, 1);
cout << onerecord->name;
}
void printSingleRecordMark(marksType *onerecord)
{
gotoxy(24, 1);
cout << onerecord->subject;
gotoxy(24, 2);
cout << onerecord->subjMarks;
}
void displayAllRecords()
{
studentType *obj1 = stuHead;
while (obj1 != NULL)
{
printSingleRecordStu(obj1);
obj1 = obj1->stu_next;
}
marksType *obj2 = mrkHead;
while (obj2 != NULL)
{
printSingleRecordMark(obj2);
obj2 = obj2->mrk_next;
}
}