From b3f82f14f32e0ab297bd31e36fddff5016e0a626 Mon Sep 17 00:00:00 2001 From: dawitbeza Date: Fri, 18 Oct 2024 09:26:28 +0300 Subject: [PATCH 1/2] changing the array that use the variable as their size to vector because the dynamic resizing rule --- .../C++ Projects/Basic/Calculate CGPA and GPA/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp index 932f14f..6e34e30 100644 --- a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp +++ b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp @@ -5,6 +5,7 @@ special right is given to TEAM TYP for educational purpose */ #include #include +#include using namespace std; @@ -58,8 +59,8 @@ void calculateGPA() cout<<" How many subject's points do you want to calculate? : "; cin>>q; - float credit [q]; - float point [q]; + std::vector credit(q); + std::vector point(q); cout<>l; cout<<"\n\n"< semrs(l); int i; for(i=0;i Date: Fri, 18 Oct 2024 13:25:53 +0300 Subject: [PATCH 2/2] changing the goto loop to while loop and introducing the new input validation techniques for all the input stream --- .../Basic/Calculate CGPA and GPA/main.cpp | 114 ++++++++++-------- 1 file changed, 67 insertions(+), 47 deletions(-) diff --git a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp index 6e34e30..6fdd01e 100644 --- a/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp +++ b/Projects/C++ Projects/Basic/Calculate CGPA and GPA/main.cpp @@ -6,17 +6,21 @@ special right is given to TEAM TYP for educational purpose */ #include #include #include +#include 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<<"--------------------------------------------------------------------------"<>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"<::max(); + int lowerGrade = 0; + int aboveGrade = 4; + int lowerCredit = 0; + int aboveCredit = 10; cout<<"-------------- GPA Calculating -----------------"<>q; + inputValidation(q, lowerArraysizePossible, bigArraySizePossible, "how many subject's points do you want to calculate"); - std::vector credit(q); - std::vector point(q); + vector credit(q); + vector point(q); cout<>credit[i]; + inputValidation(credit[i], lowerGrade, aboveGrade, "Enter the credit for the subject"); cout<>point[i]; + inputValidation(point[i], lowerGrade, aboveGrade, "Enter the point for the subject"); cout<<"-----------------------------------\n\n"<>inmenu; + inputValidation(inmenu, lowerLabeler, higherLabeler, "Your label input"); switch(inmenu) { @@ -108,27 +114,28 @@ void calculateGPA() break; case 3: exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<::max(); + int lowerGradePossible = 0;//(f) + int higherGradePossible = 4;//(A); int l; cout<<"-------------- CGPA Calculating -----------------\n\n"<>l; + inputValidation(l, lowerSemisterSizePossible, higherSemisterSizePossible, "how many semseter results do you want input"); cout<<"\n\n"< semrs(l); + vector semrs(l); int i; for(i=0;i>semrs[i]; + inputValidation(semrs[i], lowerGradePossible, higherGradePossible, "Result CGPA"); cout<<"\n"<>inmenu; + inputValidation(inmenu, lowerLabel, aboveLabel, "your label input"); switch(inmenu) { @@ -159,28 +167,26 @@ void calculateCGPA() break; case 3: exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<>inmenu; + inputValidation(inmenu, lowerLabel, aboveLabel, "your label input"); switch(inmenu) { @@ -189,9 +195,23 @@ void method() break; case 2: exit(EXIT_SUCCESS); - - default: - cout<<"\n\nYou have Entered Wrong Input!Please Choose Again!"<> 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::max(), '\n'); + } + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy