-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
172 lines (149 loc) · 3.38 KB
/
Copy pathmain.cpp
File metadata and controls
172 lines (149 loc) · 3.38 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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
struct Subject
{
string name;
int progress; // progress in percentage
};
// Function to load subjects from file
vector<Subject> loadSubjects()
{
vector<Subject> subjects;
ifstream file("study_data.txt");
if (file.is_open())
{
Subject s;
while (file >> ws && getline(file, s.name, ','))
{
file >> s.progress;
file.ignore(); // ignore newline
subjects.push_back(s);
}
file.close();
}
return subjects;
}
// Function to save subjects to file
void saveSubjects(const vector<Subject> &subjects)
{
ofstream file("study_data.txt");
for (auto &s : subjects)
{
file << s.name << "," << s.progress << endl;
}
file.close();
}
// Add a new subject
void addSubject()
{
vector<Subject> subjects = loadSubjects();
Subject s;
cout << "\nEnter subject name: ";
cin.ignore();
getline(cin, s.name);
cout << "Enter progress (0–100): ";
cin >> s.progress;
if (s.progress < 0 || s.progress > 100)
{
cout << "⚠ Invalid progress! Must be between 0–100.\n";
return;
}
subjects.push_back(s);
saveSubjects(subjects);
cout << "✅ Subject added successfully!\n";
}
// Update subject progress
void updateProgress()
{
vector<Subject> subjects = loadSubjects();
if (subjects.empty())
{
cout << "\n⚠ No subjects found! Add one first.\n";
return;
}
cout << "\nAvailable Subjects:\n";
for (size_t i = 0; i < subjects.size(); ++i)
{
cout << i + 1 << ". " << subjects[i].name << " (" << subjects[i].progress << "%)\n";
}
cout << "\nEnter subject number to update: ";
int choice;
cin >> choice;
if (choice < 1 || choice > subjects.size())
{
cout << "❌ Invalid subject number.\n";
return;
}
cout << "Enter new progress (0–100): ";
int newProgress;
cin >> newProgress;
if (newProgress < 0 || newProgress > 100)
{
cout << "⚠ Invalid progress! Must be between 0–100.\n";
return;
}
subjects[choice - 1].progress = newProgress;
saveSubjects(subjects);
cout << "✅ Progress updated successfully!\n";
}
// Show all subjects and progress
void showProgress()
{
vector<Subject> subjects = loadSubjects();
if (subjects.empty())
{
cout << "\n⚠ No subjects to show!\n";
return;
}
cout << "\n📊 Study Progress Tracker\n";
cout << left << setw(25) << "Subject" << "Progress (%)" << endl;
cout << "----------------------------------------\n";
for (auto &s : subjects)
{
cout << left << setw(25) << s.name << s.progress << "%" << endl;
}
}
// Main program menu
int main()
{
int choice;
do
{
cout << "\n===== 📘 SMART STUDY PLANNER =====\n";
cout << "1. Add Subject\n";
cout << "2. Update Progress\n";
cout << "3. Show Progress\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
if (cin.fail())
{
cin.clear();
cin.ignore(1000, '\n');
cout << "⚠ Invalid input! Please enter a number (1–4).\n";
continue;
}
switch (choice)
{
case 1:
addSubject();
break;
case 2:
updateProgress();
break;
case 3:
showProgress();
break;
case 4:
cout << "👋 Exiting Smart Study Planner...\n";
break;
default:
cout << "❌ Invalid choice! Try again.\n";
}
} while (choice != 4);
return 0;
}