-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.cpp
More file actions
102 lines (95 loc) · 3.37 KB
/
Copy pathProject.cpp
File metadata and controls
102 lines (95 loc) · 3.37 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
#include <iostream>
#include <string>
using namespace std;
// Define the student record structure
struct Student {
string name;
int age;
float marks;
};
//Function to add a new student record
void addStudent(Student students[], int& count) {
string name;
int age;
float marks;
// Prompt the user to enter the student's information
cout << "Enter student name: ";
cin >> name;
cout << "Enter student age: ";
cin >> age;
cout << "Enter student marks: ";
cin >> marks;
// Create a new student record using the entered information
Student student = { name, age, marks };
// Add the new student record to the students array
students[count++] = student;
// Display a message to indicate that the record was added successfully
cout << "Student added successfully." << endl;
}
// Function to search for a student by name
void searchStudentByName(Student students[], int count) {
string name;
// Prompt the user to enter the name of the student to search for
cout << "Enter student name: ";
cin >> name;
bool found = false;
// Search for the student by name in the students array
for (int i = 0; i < count; i++) {
if (students[i].name == name) {
// Display the student's information if they are found
cout << "Name: " << students[i].name << endl;
cout << "Age: " << students[i].age << endl;
cout << "Marks: " << students[i].marks << endl;
found = true;
break;
}
}
// Display a message if the student is not found
if (!found) {
cout << "Student not found." << endl;
}
}
// Function to print all student records
void printAllStudents(Student students[], int count) {
// Loop through the students array and display each record
system("color F1");
for (int i = 0; i < count; i++) {
cout << "Name: " << students[i].name << endl;
cout << "Age: " << students[i].age << endl;
cout << "Marks: " << students[i].marks << endl;
cout << endl;
}
}
int main() {
const int MAX_STUDENTS = 100;
Student students[MAX_STUDENTS];
int count = 0;
while (true) {
// Prompt the user to select an option
cout << "Enter option (1 to add, 2 to search, 3 to print all, 4 to exit): ";
int option;
cin >> option;
switch (option) {
case 1:
// Call the addStudent function to add a new student record
addStudent(students, count);
break;
case 2:
// Call the searchStudentByName function to search for a student by name
searchStudentByName(students, count);
break;
case 3:
// Call the printAllStudents function to print all student records
printAllStudents(students, count);
break;
case 4:
// Exit the program
cout<<"MADE BY 22CS003 - Pratham aghera "<<endl <<"\t22CS039 - Krish mavani"<<endl <<"\t22CS092 - Sujal vekariya"<<endl;
return 0;
default:
// Display an error message if an invalid option is selected
cout << "Invalid option." << endl;
}
}
return 0;
}