Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature in c++ project cgpa #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 68 additions & 47 deletions Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ special right is given to TEAM TYP for educational purpose */

#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>

using namespace std;

void calculateGPA();
void calculateCGPA();
void method();
void inputValidation(int& input, int lowerInputLeveler, int aboveInputLeveler, const string& labelMessage);

int main()
{
system("cls");
int input;
int aboveLabel = 4;
int lowerLabel = 1;
cout<<"--------------------------------------------------------------------------"<<endl;
cout<<" GPA & CGPA Calculator (Developed by Nemo) "<<endl;
cout<<"--------------------------------------------------------------------------\n"<<endl;
Expand All @@ -25,50 +30,52 @@ int main()
cout<<" 3. Method that is applied here for calclating GPA & CGPA"<<endl;
cout<<" 4. Exit Application"<<endl;
cout<<"--------------------------------------------------------------------------"<<endl;
sub:
cout<<"Enter your choice: ";
cin>>input;
switch(input)
{
cout << "Enter your choice: ";
inputValidation(input, lowerLabel, aboveLabel, "Ente your choice");
switch (input)
{
case 1:
calculateGPA();
break;
calculateGPA();
break;

case 2:
calculateCGPA();
break;
calculateCGPA();
break;
case 3:
method();
break;
method();
break;
case 4:
exit(EXIT_SUCCESS);
break;
default:
cout<<"You have entered wrong input.Try again!\n"<<endl;
goto sub;
exit(EXIT_SUCCESS);
break;
}
}
}

void calculateGPA()
{
int q;
system("cls");
//in this case the validation is not made to label rather the size of array, we make the lower 1 because we cannot calculate anything for 0 subjects
int lowerArraysizePossible = 1;
int bigArraySizePossible = numeric_limits<int>::max();
int lowerGrade = 0;
int aboveGrade = 4;
int lowerCredit = 0;
int aboveCredit = 10;
cout<<"-------------- GPA Calculating -----------------"<<endl;
cout<<" How many subject's points do you want to calculate? : ";
cin>>q;
inputValidation(q, lowerArraysizePossible, bigArraySizePossible, "how many subject's points do you want to calculate");

float credit [q];
float point [q];
vector<int> credit(q);
vector<int> point(q);

cout<<endl;
for(int i=0;i<q;i++)
{
cout<<"Enter the credit for the subject "<<i+1<<": ";
cin>>credit[i];
inputValidation(credit[i], lowerGrade, aboveGrade, "Enter the credit for the subject");
cout<<endl;
cout<<"Enter the point of the subject "<<i+1<<": ";
cin>>point[i];
inputValidation(point[i], lowerGrade, aboveGrade, "Enter the point for the subject");
cout<<"-----------------------------------\n\n"<<endl;
}

Expand All @@ -87,15 +94,15 @@ void calculateGPA()
}

cout<<"\n\n\nTotal Points: "<<sum<<" . Total Credits: "<<totCr<<" .Total GPA: "<<sum/totCr<<" ."<<endl;


sub:
//there are 3 labeles to be validated
int lowerLabeler = 1;
int higherLabeler = 4;
int inmenu;
cout<<"\n\n\n1. Calculate Again"<<endl;
cout<<"2. Go Back to Main Menu"<<endl;
cout<<"3. Exit This App \n\n"<<endl;
cout<<"Your Input: "<<endl;
cin>>inmenu;
inputValidation(inmenu, lowerLabeler, higherLabeler, "Your label input");

switch(inmenu)
{
Expand All @@ -107,27 +114,28 @@ void calculateGPA()
break;
case 3:
exit(EXIT_SUCCESS);

default:
cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<<endl;
goto sub;
}
}
void calculateCGPA()
{
system("cls");
//the validation parameter for the semister size and the grade input
int lowerSemisterSizePossible = 2;
int higherSemisterSizePossible = numeric_limits<int>::max();
int lowerGradePossible = 0;//(f)
int higherGradePossible = 4;//(A);
int l;
cout<<"-------------- CGPA Calculating -----------------\n\n"<<endl;
cout<<"How many semester results do you want input? :";
cin>>l;
inputValidation(l, lowerSemisterSizePossible, higherSemisterSizePossible, "how many semseter results do you want input");
cout<<"\n\n"<<endl;
float semrs[l];
vector<int> semrs(l);
int i;

for(i=0;i<l;i++)
{
cout<<" Enter Semester "<<i+1<<" Result(GPA): ";
cin>>semrs[i];
inputValidation(semrs[i], lowerGradePossible, higherGradePossible, "Result CGPA");
cout<<"\n"<<endl;
}

Expand All @@ -137,16 +145,17 @@ void calculateCGPA()
semtot=semtot+semrs[j];
}

cout<<"******** Your CGPA is "<<semtot/l<<" **********"<<endl;

//the validation paramater for the label
int lowerLabel = 1;
int aboveLabel = 3;

sub:
cout << "******** Your CGPA is " << semtot / l << " **********" << endl;
int inmenu;
cout<<"\n\n\n1. Calculate Again"<<endl;
cout<<"2. Go Back to Main Menu"<<endl;
cout<<"3. Exit This App \n\n"<<endl;
cout<<"Your Input: "<<endl;
cin>>inmenu;
inputValidation(inmenu, lowerLabel, aboveLabel, "your label input");

switch(inmenu)
{
Expand All @@ -158,28 +167,26 @@ void calculateCGPA()
break;
case 3:
exit(EXIT_SUCCESS);

default:
cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<<endl;
goto sub;
}

}

void method()
{
//since there are only two leveles that are (go back to mainmenu and exit app)
int lowerLabel = 1;
int aboveLabel = 2;
system("cls");
cout<<"--------------- Method of Calculating GPA & CGPA ---------------\n\n"<<endl;
cout<<" GPA= Sum of (Credit*Point) / total of credits \n"<<endl;
cout<<" CGPA= Sum of GPA / number of semesters "<<endl;
cout<<"-----------------------------------------------------------------\n\n"<<endl;

sub:
int inmenu;
cout<<"1. Go Back to Main Menu"<<endl;
cout<<"2. Exit This App \n\n"<<endl;
cout<<"Your Input: "<<endl;
cin>>inmenu;
inputValidation(inmenu, lowerLabel, aboveLabel, "your label input");

switch(inmenu)
{
Expand All @@ -188,9 +195,23 @@ void method()
break;
case 2:
exit(EXIT_SUCCESS);

default:
cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<<endl;
goto sub;
}
};

void inputValidation(int& input, int lowerBound, int upperBound, const std::string& labelMessage) {
while (true) {
if (std::cin >> input) {
if (input >= lowerBound && input <= upperBound) {
break;
}
else {
std::cout << "Please enter a number between " << lowerBound << " and " << upperBound << " (" << labelMessage << ")" << std::endl;
}
}
else {
std::cout << "Invalid input. Please enter a valid number (" << labelMessage << ")" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
}