-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.cpp
More file actions
205 lines (170 loc) · 5.89 KB
/
Copy pathtempCodeRunnerFile.cpp
File metadata and controls
205 lines (170 loc) · 5.89 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib> // For system() function
#include <unistd.h> // For UNIX system detection (Linux/macOS)
#include <windows.h> // For Windows system detection
using namespace std;
// Structure to hold student data
struct Student {
string prn;
string name;
string password;
};
// Structure to hold subject data
struct Subject {
string name;
int year;
int semester;
string syllabusFile;
};
// Structure to hold paper data
struct Paper {
string subjectName;
int year;
int semester;
string paperFile;
};
// Function to validate student login
bool validateLogin(const string& prn, const string& password) {
ifstream file("students.txt");
string storedPrn, storedName, storedPassword;
while (file >> storedPrn >> storedName >> storedPassword) {
if (prn == storedPrn && password == storedPassword) {
return true;
}
}
return false;
}
// Function to get the OS type
string getOperatingSystem() {
#if defined(_WIN32) || defined(_WIN64)
return "Windows";
#elif defined(__linux__)
return "Linux";
#elif defined(__APPLE__) || defined(__MACH__)
return "macOS";
#else
return "Unknown";
#endif
}
// Function to open a PDF file based on the operating system
void openPDF(const string& filePath) {
string os = getOperatingSystem();
if (os == "Windows") {
system(("start " + filePath).c_str()); // Windows command to open PDF
} else if (os == "Linux") {
system(("xdg-open " + filePath).c_str()); // Linux command to open PDF
} else if (os == "macOS") {
system(("open " + filePath).c_str()); // macOS command to open PDF
} else {
cout << "Unsupported OS. Cannot open PDF." << endl;
}
}
// Function to display syllabus for a given subject
void displaySyllabus(const string& subjectName) {
ifstream file("syllabus.txt");
string subject, syllabusFile;
while (file >> subject >> syllabusFile) {
if (subject == subjectName) {
cout << "Syllabus for " << subjectName << ": " << syllabusFile << endl;
// Open the PDF file using the appropriate system command
openPDF(syllabusFile);
return;
}
}
cout << "Syllabus for " << subjectName << " not found.\n";
}
// Function to display subjects for a given year and semester
void displaySubjects(int year, int semester) {
ifstream file("subjects.txt");
string subjectName;
int subjectYear, subjectSemester;
cout << "\nSubjects for Year " << year << " Semester " << semester << ":\n";
while (file >> subjectName >> subjectYear >> subjectSemester) {
if (subjectYear == year && subjectSemester == semester) {
cout << "- " << subjectName << endl;
}
}
}
// Function to display past papers for a given subject
void displayPapers(const string& subjectName, int year, int semester) {
ifstream file("papers.txt");
if (!file) {
cout << "Error: papers.txt file not found.\n";
return;
}
string subject, paperFile;
int paperYear, paperSemester;
cout << "\nPast Papers for " << subjectName << " (" << year << " Semester " << semester << "):\n";
bool foundPaper = false; // Flag to check if we found any paper
while (file >> subject >> paperYear >> paperSemester >> paperFile) {
if (subject == subjectName && paperYear == year && paperSemester == semester) {
foundPaper = true;
cout << "- " << paperFile << endl;
// Ask the user if they want to open the PDF
char choice;
cout << "Do you want to open previous year question paper for this? (y/n): ";
cin >> choice;
if (choice == 'y' || choice == 'Y') {
// Construct the full path to the paper (assuming papers are stored in the "papers" folder)
string fullPath = "papers/" + paperFile;
// Open the PDF file using the appropriate system command
openPDF(fullPath); // Open the PDF with the correct path
}
}
}
if (!foundPaper) {
cout << "No past papers found for " << subjectName << " (" << year << " Semester " << semester << ").\n";
}
}
// Main function
int main() {
string prn, password;
// Student login
cout << "Welcome to Edutrack!\n";
cout << "Please enter your PRN: ";
cin >> prn;
cout << "Please enter your password: ";
cin >> password;
if (!validateLogin(prn, password)) {
cout << "Invalid PRN or password. Exiting...\n";
return 0;
}
cout << "Login successful! Welcome, " << prn << ".\n";
int year, semester;
string subjectName;
// Main Menu
while (true) {
cout << "\nSelect Year (1-4): ";
cin >> year;
if (year < 1 || year > 4) {
cout << "Invalid year. Please try again.\n";
continue;
}
cout << "Select Semester (1-2): ";
cin >> semester;
if (semester < 1 || semester > 2) {
cout << "Invalid semester. Please try again.\n";
continue;
}
// Display subjects for the selected year and semester
displaySubjects(year, semester);
// Select a subject
cout << "\nEnter a subject name to view syllabus and past papers: ";
cin.ignore(); // To handle the newline character left in the buffer
getline(cin, subjectName);
// Display syllabus for the selected subject
displaySyllabus(subjectName);
// Display past papers for the selected subject
displayPapers(subjectName, year, semester);
char choice;
cout << "\nDo you want to continue? (y/n): ";
cin >> choice;
if (choice == 'n' || choice == 'N') {
break;
}
}
cout << "\nThank you for using Edutrack. Goodbye!\n";
return 0;
}