Project Code

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

PROJECT CODE

#include <iostream>

#include <string>

using namespace std;

struct Student {

string name;

int rollNumber;

string course;

string className;

};

const int MAX_STUDENTS = 100;

Student students[MAX_STUDENTS];

int studentCount = 0;

void addStudent() {

if (studentCount >= MAX_STUDENTS) {

cout << "\nCannot add more students. Maximum limit reached." << endl;

return;

cout << "\nEnter student name: ";

cin >> students[studentCount].name;

cout << "Enter roll number: ";


cin >> students[studentCount].rollNumber;

cout << "Enter course: ";

cin >> students[studentCount].course;

cout << "Enter class: ";

cin >> students[studentCount].className;

studentCount++;

void displayStudents() {

if (studentCount == 0) {

cout << "No students have been added yet." << endl;

return;

cout << "\nStudent Records:" << endl;

for (int i = 0; i < studentCount; i++) {

cout << "------------------------" << endl;

cout << "Name: " << students[i].name << endl;

cout << "Roll Number: " << students[i].rollNumber << endl;

cout << "Course: " << students[i].course << endl;

cout << "Class: " << students[i].className << endl;

cout << "------------------------" << endl;

}
void searchStudent() {

int rollNumber;

cout << "Enter roll number to search: ";

cin >> rollNumber;

bool found = false;

for (int i = 0; i < studentCount; i++) {

if (students[i].rollNumber == rollNumber) {

cout << "Student Found:" << endl;

cout << "Name: " << students[i].name << endl;

cout << "Roll Number: " << students[i].rollNumber << endl;

cout << "Course: " << students[i].course << endl;

cout << "Class: " << students[i].className << endl;

found = true;

break;

if (!found) {

cout << "Student not found." << endl;

void updateStudent() {

int rollNumber;
cout << "Enter roll number to update: ";

cin >> rollNumber;

bool found = false;

for (int i = 0; i < studentCount; i++) {

if (students[i].rollNumber == rollNumber) {

cout << "Enter new name: ";

cin >> students[i].name;

cout << "Enter new course: ";

cin >> students[i].course;

cout << "Enter new class: ";

cin >> students[i].className;

found = true;

break;

if (!found) {

cout << "Student not found." << endl;

void deleteStudent() {

int rollNumber;

cout << "Enter roll number to delete: ";

cin >> rollNumber;


bool found = false;

for (int i = 0; i < studentCount; i++) {

if (students[i].rollNumber == rollNumber) {

// Shift all elements to the left

for (int j = i; j < studentCount - 1; j++) {

students[j] = students[j + 1];

studentCount--;

found = true;

break;

if (!found) {

cout << "Student not found." << endl;

void deleteAllStudents() {

studentCount = 0;

cout << "All student records have been deleted." << endl;

int main() {

int choice;
do {

cout << "\nStudent Record Management System" << endl;

cout << "1. Add Student" << endl;

cout << "2. Display Students" << endl;

cout << "3. Search Student" << endl;

cout << "4. Update Student" << endl;

cout << "5. Delete Student" << endl;

cout << "6. Delete All Students" << endl;

cout << "7. Exit" << endl;

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case 1:

addStudent();

break;

case 2:

displayStudents();

break;

case 3:

searchStudent();

break;

case 4:

updateStudent();
break;

case 5:

deleteStudent();

break;

case 6:

deleteAllStudents();

break;

case 7:

cout << "Exiting the program." << endl;

break;

default:

cout << "Invalid choice. Please try again." << endl;

} while (choice != 7);

return 0;

You might also like