You are on page 1of 3

main.

cpp
#include <iostream>
#include <string>
using namespace std;

void add(int &num, int nextNum){


num += nextNum;
}

void blockNoSecondYear(int num, int i, int j, char &noSecondYear){


if (j == 1 && num == 0){
char letter = 97 + i;
noSecondYear = toupper(letter);
}
}
void batchFunction(int num, int i, int j, int batchArray[]){
batchArray[j] += num;
}
string studentYear(int j){
string batchs[5] = {"first", "second", "third", "fourth", "fifth"};
return batchs[j];
}
char studentBlock(int i){
char letter = 97 + i;
char block = toupper(letter);
return block;
}
string suffix(int j){
string arr[3]={"st","nd","rd"};
return j<3?arr[j]:"th";
}

void maxBlock(int &large, int current, int i,char &largestBlockIs){


if (current >= large){
large = current;
largestBlockIs=studentBlock(i);
}
}
void minBlock(int &small, int current, int i,char &smallestBlockIs){
if (i == 0 || current <= small){
small = current;
smallestBlockIs=studentBlock(i);
}
}
void maxBatch(int &large, int current, int i,string &largestBatchIs)
{
if (current >= large){
large = current;
largestBatchIs=studentYear(i);
}
}
void minBatch(int &small, int current, int i,string &smallestBatchIs){
if (i == 0 || current <= small){
small = current;
smallestBatchIs=studentYear(i);
}
}
void dataHandler(string studentData[][4], int numOfstnds){
for(int k=0; k<numOfstnds; k++){
string name, age, gender,id;
cout <<k+1<<"\\"<<numOfstnds<<", Enter the name of the student [Name_FatherName]: ";
cin >> name;
cout << "Enter age of "<<name<<": ";
cin >> age;
cout << "Enter gender of "<<name<<" [male/female]: ";
cin >> gender;
cout << "Enter id of "<<name<<" [ets****/**]: ";
cin >> id;
cout << "\n...........................\n\n";
studentData[k][0] = name;
studentData[k][1] = age;
studentData[k][2] = gender;
studentData[k][3] = id;
}
}

main.cpp 1
int main(){
B:
const int x = 6, y = 5,MAX_NUM=1000;
int totalNumOfStudents = 0, largestBlock = 0, smallestBlock = 0,
largestBatch = 0, smallestBatch = -1, eachBatch[y]={0,0,0,0,0}, z = 0, menu;
char noSecondYearBlock, largestBlockIs, smallestBlockIs;
string studentData[MAX_NUM][4],largestBatchIs, smallestBatchIs, outputText[4]={"name","age","gender","ID"};
int blocks[x][y];

//data to be inserted{{10, 25, 30, 11, 12},{0, 23, 9, 10, 11},{7, 44, 77, 0, 8},{8, 3, 0, 8, 12},{11, 20, 4, 11, 0},{0, 0, 10, 20, 3
for (int i = 0; i < x; i++){
for (int j = 0; j < y; j++){
cout<<"Enter The number of "<<studentYear(j)<<" year students in Block "<<studentBlock(i)<<": ";
cin>>blocks[i][j];
}
cout<<"\n";
}
cout<<"done\n\n";

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


int sumOfTheCurrentBlock = 0;
for (int j = 0; j < y; j++){
add(sumOfTheCurrentBlock, blocks[i][j]);
blockNoSecondYear(blocks[i][j], i, j, noSecondYearBlock);
batchFunction(blocks[i][j], i, j, eachBatch);
z++;
}
add(totalNumOfStudents, sumOfTheCurrentBlock);
maxBlock(largestBlock, sumOfTheCurrentBlock, i, largestBlockIs);
minBlock(smallestBlock, sumOfTheCurrentBlock, i, smallestBlockIs);
}
A:
cout<<"\n[1] for entering tabular data [2] for registering each student [3] block with largest number of students"
"\n[4] the block with smallest number of students [5] total number of students "
" [6] students in each batch\n[7] a block with no second year student [8] a batch with greatest number of students"
"\n[9] a batch with smallest number of students [10] display students data\n\nEnter a number: ";
cin>>menu;
cout<<endl;
switch (menu){
case 1:
goto B;
break;
case 2:
dataHandler(studentData, totalNumOfStudents);
break;
case 3:
cout << "A block with greatest number of students: " << largestBlockIs << endl;
break;
case 4:
cout << "A block with smallest number of students is: " << smallestBlockIs << endl;
break;
case 5:
cout << "The total number of students is " << totalNumOfStudents << endl;
break;
case 6:
for (int i = 0; i < 5; i++){
cout << "number of students in " << studentYear(i) << " batch: " << eachBatch[i] << endl;
maxBatch(largestBatch, eachBatch[i], i, largestBatchIs);
minBatch(smallestBatch, eachBatch[i], i, smallestBatchIs);
}
break;
case 7:
cout << "A block that doesn't have second year students: " << noSecondYearBlock << endl;
break;
case 8:
cout << "A batch with greatest number of students: " << largestBatchIs <<" batch"<<endl;
break;
case 9:
cout << "A batch with smallest number of students is: " << smallestBatchIs<<" batch"<< endl;
break;
case 10:
for(int i=0; i<totalNumOfStudents; i++){
for(int j=0; j<4; j++){
cout<<outputText[j]<<": "<<studentData[i][j]<<"\n";
}
cout<<endl;
}
break;
default:
break;

main.cpp 2
}
goto A;
return 0;
}

main.cpp 3

You might also like