0% found this document useful (0 votes)
16 views11 pages

Itcproject 0255

This document contains the main function of a C++ program that manages student records in arrays. The program allows the user to sort and display the records by roll number, midterm marks, final marks, or grade in ascending or descending order. It also allows the user to add or delete records and filter records based on marks or grade thresholds. The main menu is displayed and the user can select an option to perform the desired task on the student records.

Uploaded by

mazharyt1840
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

Itcproject 0255

This document contains the main function of a C++ program that manages student records in arrays. The program allows the user to sort and display the records by roll number, midterm marks, final marks, or grade in ascending or descending order. It also allows the user to add or delete records and filter records based on marks or grade thresholds. The main menu is displayed and the user can select an option to perform the desired task on the student records.

Uploaded by

mazharyt1840
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

// itcproject0255.cpp : This file contains the 'main' function.

Program execution
begins and ends there.
//

// ConsoleApplication1.cpp : This file contains the 'main' function. Program


execution begins and ends there.
//

#include <iostream>
using namespace std;
int main()
{
const int ARRAY_SIZE = 100;
int rollNumbers[ARRAY_SIZE] = { 73, 42, 91, 28, 15, 68, 37, 54, 89, 63, 12, 76,
98, 24, 51, 84, 19, 33, 77, 46, 59, 81, 36, 22, 67, 93, 58, 14, 72, 31, 88, 49, 26,
61, 82, 18, 95, 29, 44, 71, 97, 23, 39, 66, 13, 78, 55, 86, 32 };
float midtermMarks[ARRAY_SIZE] = { 25.5, 18.8, 36.3, 29.1, 41.7, 14.2, 38.6,
56.7, 30.9, 48.2, 19.4, 33.8, 22.6, 45.3, 39.8, 17.2, 27.5, 12.8, 37.4, 44.6, 52.9,
21.4, 31.7, 49.3, 15.6, 24.8, 40.1, 35.7, 50.5, 16.9, 28.3, 42.9, 34.6, 23.7, 19.2,
54.6, 11.3, 46.9, 38.1, 58.4, 26.2, 32.4, 14.8, 43.7, 51.1, 49.7, 29.8, 37.2,
20.3 };
float finalMarks[ARRAY_SIZE] = { 85.3, 78.6, 93.2, 67.1, 76.8, 89.4, 82.1,
94.7, 71.5, 64.2, 78.9, 90.6, 84.3, 97.8, 73.4, 65.9, 79.2, 88.7, 91.4, 74.6, 62.1,
87.5, 80.3, 69.7, 96.2, 82.9, 75.6, 70.4, 94.1, 68.2, 81.7, 77.9, 92.3, 86.5, 79.8,
83.6, 95.6, 72.3, 76.1, 60.9, 99.2, 66.7, 84.9, 92.8, 98.4, 61.5, 63.7, 89.9,
80.5 };
int studentClass[ARRAY_SIZE] = { 3, 2, 1, 3, 2, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2,
3, 1, 2, 3, 1 };
char grades[ARRAY_SIZE] = { 'B', 'C', 'A', 'B', 'C', 'A', 'C', 'B', 'A', 'B',
'A', 'C', 'B', 'A', 'B', 'C', 'A', 'B', 'C', 'B', 'A', 'C', 'B', 'A', 'C', 'B',
'A', 'C', 'B', 'A', 'C', 'B', 'A', 'C', 'B', 'A', 'C', 'B', 'A', 'C', 'B', 'A',
'C', 'B', 'A', 'C', 'B', 'A', 'C', 'B', 'A' };

char choice;
int curr_size = 50;
do {
cout << "\nMain Menu:\n";
cout << "Press '1' to Sort and display all records roll number wise in
ascending order.\n";
cout << "Press '2' to Sort and display all records roll number wise in
descending order.\n";
cout << "Press '3' to Sort and display all records in ascending order based
on marks in Midterm.\n";
cout << "Press '4' to Sort and display all records in descending order
based on marks in Midterm.\n";
cout << "Press '5' to Sort and display all records in ascending order based
on marks in Final.\n";
cout << "Press '6' to Sort and display all records in descending order
based on marks in Final.\n";
cout << "Press '7' to Sort and display all records in ascending order based
on Grade.\n";
cout << "Press '8' to Sort and display all records in descending order
based on Grade.\n";
cout << "Press '9' to Add a new entry of a student.\n";
cout << "Press '10' to Delete a student record based on his roll number.\
n";
cout << "Press '11' to Display record of all the students greater than X
marks in final exam (in descending order with respect to marks obtained in final
exam).\n";
cout << "Press '12' to Display record of all the students greater than X
marks in final exam (in ascending order with respect to marks obtained in final
exam).\n";
cout << "Press '13' to Display record of all the students less than or
equal to X marks in final exam (in descending order with respect to marks obtained
in final exam).\n";
cout << "Press '14' to Display record of all the students less than or
equal to X marks in final exam (in ascending order with respect to marks obtained
in final exam).\n";
cout << "Press '15' to Display record of all the students greater than X
grade (in descending order with respect to grade).\n";
cout << "Press '16' to Display record of all the students greater than X
grade (in ascending order with respect to grade).\n";
cout << "Press '17' to Display record of all the students less than or
equal to X grade (in descending order with respect to grade).\n";
cout << "Press '18' to Display record of all the students less than or
equal to X grade (in ascending order with respect to grade).\n";
cout << "Press 'E' to Exit\n";
cout << "Enter your choice: ";
cin >> choice;

int deleteIndex = -1;


int threshold = 0;
char thres = 0;
switch (choice)
{
case '1':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (rollNumbers[j] > rollNumbers[j + 1])
{

swap(rollNumbers[j], rollNumbers[j + 1]);


swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}

cout << "\nSorted Records in Ascending Order:\n";


for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '2':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (rollNumbers[j] < rollNumbers[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Descending Order:\n";
for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '3':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (midtermMarks[j] > midtermMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Ascending Order based on Midterm Marks:\
n";
for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '4':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (midtermMarks[j] < midtermMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Descending Order based on Midterm Marks:\
n";
for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '5':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] > finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Ascending Order based on Final Marks:\n";
for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '6':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] < finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Descending Order based on Final Marks:\n";
for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '7':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] > grades[j + 1])
{

swap(rollNumbers[j], rollNumbers[j + 1]);


swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Ascending Order based on Grade:\n";
for (int i = 0; i < curr_size; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '8':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] > grades[j + 1]) {
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Ascending Order based on Grade:\n";
for (int i = 0; i < curr_size; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '9':
for (int i = 0; i < curr_size - 1; ++i)
{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] > grades[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
cout << "\nSorted Records in Ascending Order based on Grade:\n";
for (int i = 0; i < curr_size; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '10':
float threshold;
cout << "Enter the threshold for final exam marks: ";
cin >> threshold;

std::cout << "\nRecords with Final Exam Marks greater than " <<
threshold << " (Descending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] < finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size; ++i)
{
if (finalMarks[i] > threshold)
{
std::cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
}
break;

case '11':
cout << "Enter the threshold for final exam marks: ";
cin >> threshold;

cout << "\nRecords with Final Exam Marks greater than " << threshold <<
" (Descending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] < finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && finalMarks[i] > threshold; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '12':
cout << "Enter the threshold for final exam marks: ";
cin >> threshold;

cout << "\nRecords with Final Exam Marks greater than " << threshold <<
" (Ascending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] > finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && finalMarks[i] > threshold; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '13':
cout << "Enter the threshold for final exam marks: ";
cin >> threshold;

cout << "\nRecords with Final Exam Marks less than or equal to " <<
threshold << " (Descending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] < finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && finalMarks[i] <= threshold; ++i) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '14':
cout << "Enter the threshold for final exam marks: ";
cin >> threshold;

cout << "\nRecords with Final Exam Marks less than or equal to " <<
threshold << " (Ascending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (finalMarks[j] > finalMarks[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && finalMarks[i] <= threshold; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '15':
cout << "Enter the threshold grade (character): ";
cin >> thres;

cout << "\nRecords with Grade greater than " << thres << " (Descending
Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] < grades[j + 1])
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && grades[i] > thres; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '16':
cout << "Enter the threshold grade (character): ";
cin >> thres;

cout << "\nRecords with Grade greater than " << thres << " (Ascending
Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] > thres)
{
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && grades[i] > thres; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '17':
float thres;
cout << "Enter the threshold grade (character): ";
cin >> thres;

cout << "\nRecords with Grade less than or equal to " << thres << "
(Descending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] < thres) {
swap(rollNumbers[j], rollNumbers[j + 1]);
swap(midtermMarks[j], midtermMarks[j + 1]);
swap(finalMarks[j], finalMarks[j + 1]);
swap(studentClass[j], studentClass[j + 1]);
swap(grades[j], grades[j + 1]);
}
}
}
for (int i = 0; i < curr_size && grades[i] <= thres; ++i)
{
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
break;

case '18':
cout << "Enter the threshold grade (character): ";
cin >> thres;

cout << "\nRecords with Grade less than or equal to " << thres << "
(Ascending Order):\n";

for (int i = 0; i < curr_size - 1; ++i)


{
for (int j = 0; j < curr_size - i - 1; ++j)
{
if (grades[j] > thres)
{
// Swap the records manually
int tempRoll = rollNumbers[j];
rollNumbers[j] = rollNumbers[j + 1];
rollNumbers[j + 1] = tempRoll;

float tempMidterm = midtermMarks[j];


midtermMarks[j] = midtermMarks[j + 1];
midtermMarks[j + 1] = tempMidterm;
float tempFinal = finalMarks[j];
finalMarks[j] = finalMarks[j + 1];
finalMarks[j + 1] = tempFinal;

int tempClass = studentClass[j];


studentClass[j] = studentClass[j + 1];
studentClass[j + 1] = tempClass;

char tempGrade = grades[j];


grades[j] = grades[j + 1];
grades[j + 1] = tempGrade;
}
}
}
for (int i = 0; i < curr_size; ++i)
{
if (grades[i] <= thres) {
cout << "Roll No: " << rollNumbers[i]
<< " Midterm Marks: " << midtermMarks[i]
<< " Final Marks: " << finalMarks[i]
<< " Class: " << studentClass[i]
<< " Grade: " << grades[i] << "\n";
}
}
break;

case 'E':
case 'e':
cout << "Exiting the program.\n";
break;
default:
cout << "Invalid choice. Please enter a valid option.\n";
}

} while (choice != 'E' && choice != 'e');

return 0;
}

You might also like