Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
My only guess is I should be using getline(cin, var) instead of just cin but i played with //it and had no success .
C++
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <conio.h>
#include <cstring>

using namespace std;



// Global constants
const int CLASS = 4,
			COLS = 4, //columns in each array
			  ROWS = 4, //rows in table
				NEW_GRADE = 24;

//simple splash screen
void goSplash();
//yes that is seven variables sent the menu function
void showMenu( const int , const int, const int ,const int ,const int ,const int ,int &);
//my bubble sort
void goSort(int[] , const int);


 int main()
 {
 //constants for the menu 
	 const int CLASS1 = 1,//constants for menu information
		CLASS2  = 2, 
		CLASS3 = 3,
		CLASS4 = 4,
		CLASS5 = 5,
		CLASS_ALL = 6;

	 //hold the value of the choice for the user and 
	 int choice;

		//new grades arrays
		int newGrade[CLASS];
		


	
	 //string array for class names
	string classArray[CLASS];//string array for class names
	
	//integer 2d array for class percentages
	int tableGrade[ROWS][COLS];

//program intro a basic information intro with a pause and a screen clear
cout <<"\nThis program will allow you to view and manipulate your,\n";
cout<<"test scores in in four quarter semester.\n";
cout<<"Your will list four subjects and or classes and than your scores.\n";
cout<<"Your can view your scores, average them or sort them by class."<<endl;
cout<<"\nPLEASE PRESS ENTER TO START PROGRAM"<<endl;
//pause and clear
_getch();
system("CLS");

//splash screen
goSplash();

	//add names to the classes array
	for (int count = 0; count < CLASS; count++)
	 {
	 cout <<"\nEnter the name of class ("<<count + 1<<") : ";
	 cin>>classArray[count];
		}
		
	//these for loops where easy without the validation to make them massive
	//I needed to fill five rows and five columns with percentages
	for (int val = 0, num = 0; val < COLS; val ++)
		{
			do  
			{ 
			cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
			cin >> tableGrade[num][val]; 
			
				while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
				{
					cout<<"The value must be between 0 and 100: ";
					cin >> tableGrade[num][val];
					cout<<"\n";
				}	
				

				if (cin.fail())  
				{
					cin.clear();  
					cin.ignore(INT_MAX, '\n'); 
				}

				}while (cin.fail());	
			
			}

	for (int val = 0, num = 1; val < COLS; val ++)
	{
		do  
		{ 
			cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
			cin >> tableGrade[num][val]; 

			while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
			{
				cout<<"The value must be between 0 and 100: ";
				cin >> tableGrade[num][val];
				cout<<"\n";
			}	


			if (cin.fail())  
			{
				cin.clear();  
				cin.ignore(INT_MAX, '\n'); 
			}

		}while (cin.fail());	

	}

	for (int val = 0, num = 2; val < COLS; val ++)
	{
		do  
		{ 
			cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
			cin >> tableGrade[num][val]; 

			while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
			{
				cout<<"The value must be between 0 and 100: ";
				cin >> tableGrade[num][val];
				cout<<"\n";
			}	


			if (cin.fail())  
			{
				cin.clear();  
				cin.ignore(INT_MAX, '\n'); 
			}

		}while (cin.fail());	

	}
	for (int val = 0, num = 3; val < COLS; val ++)
	{
		do  
		{ 
			cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
			cin >> tableGrade[num][val]; 

			while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
			{
				cout<<"The value must be between 0 and 100: ";
				cin >> tableGrade[num][val];
				cout<<"\n";
			}	


			if (cin.fail())  
			{
				cin.clear();  
				cin.ignore(INT_MAX, '\n'); 
			}

		}while (cin.fail());	

	}
	for (int val = 0, num = ROWS; val < COLS; val ++)
	{
		do  
		{ 
			cout <<"\nEnter score number "<<num +1<<" in percent out of 100 for "<< classArray[val]<<" : ";
			cin >> tableGrade[num][val]; 

			while (tableGrade[num][val] < 0 || tableGrade[num][val] > 100)
			{
				cout<<"The value must be between 0 and 100: ";
				cin >> tableGrade[num][val];
				cout<<"\n";
			}	


			if (cin.fail())  
			{
				cin.clear();  
				cin.ignore(INT_MAX, '\n'); 
			}

		}while (cin.fail());	

	}
	
	showMenu(CLASS1, CLASS2, CLASS3, CLASS4, CLASS5, CLASS_ALL, choice);

	while (choice < 1 || choice > 7)
	{
	cout<"Please choose an option from 1 to 6: ";
	cin>>choice;
		if (choice==7)
		{
			system("PAUSE");
			exit;
		}
	}

	//large switch statement where I decided to send the out of the 2d arrays 
	switch (choice)
	{
	case 1:
		cout <<"Your Grades for "<< classArray[0] << " are.\n";
		for (int num =0; num < COLS; num++ )
		{
			cout<<"Grade: "<<num +1<< tableGrade[num][0]<<"\n";
		}
	break;
	case 2:
		cout <<"Your Grades for "<< classArray[1] << " are.\n";
		for (int num =0; num < COLS; num++ )
		{

			cout<<"Grade: %"<<num +1<< tableGrade[num][1]<<"\n";
		}
		break;
	case 3:
		cout <<"Your Grades for "<< classArray[2] << " are.\n";
		for (int num =0; num < COLS; num++ )
		{
			cout<<"Grade: %"<<num +1<< tableGrade[num][2]<<"\n";
		}
	break;
	case 4:
		cout <<"Your Grades for "<< classArray[3] << " are.\n";
		for (int num =0; num < COLS; num++ )
		{

			cout<<"Grade: "<<num +1<< tableGrade[num][3]<<"\n";
			
		}
	case 5:
		cout <<"Your Grades for "<< classArray[4] << " are.\n";
		for (int num =0; num < COLS; num++ )
		{

			cout<<"Grade: "<<num +1<< tableGrade[num][4]<<"\n";
			
		}
	
	//side ways for loops cool. to dump my 2d into a one dimension arrays than send them to the sort function
	case 6:
		cout<<"The sorted grades for your classes are.\n";
		for(int var = 0, big =0; var < COLS; var ++, big++){newGrade[big] = tableGrade[0][var]; }
		for(int var = 0,  big =5; var < COLS; var ++, big++){newGrade[big] = tableGrade[1][var]; }
		for(int var = 0, big =10;  var < COLS; var ++, big++){newGrade[big] = tableGrade[2][var]; }
		for(int var = 0, big = 15; var < COLS; var ++, big++){newGrade[big] = tableGrade[3][var]; }
		for(int var = 0, big = 20; var < COLS; var ++, big++){newGrade[big] = tableGrade[4][var]; }
		
		//sort the large grade table
		goSort(newGrade, NEW_GRADE);
			break;
	default:
		cout<<"Error invalid input entered"<<endl;
		break;
	}

cout<<"Do you wish to exit the program now\n";
cout<<
 system("PAUSE");
 
 exit;
 }

 //while loop decrementing with some symbols
 void goSplash()
 { 
	 int count = 1000;
	 while (count > 0)
	 {
		count--; 
		 cout<<"101101111100000001101010010100100100111110010101001010101110101";
			if (count%5==0)
			{
				cout<<"%^%&^(^&(^*%^%*%%^$(^&%^$*$*$%*$%*%**%*";
			}
	 }
	 cout<<setw(50)<<"CHRIS'S GRADE KEEPER";
	 system("CLS");
 }
 
 void showMenu(const int CLASS1, const int CLASS2, const int CLASS3, const int CLASS4, const int CLASS5, const int CLASS_ALL, int &choice)
 {
	 const int EXIT = 7;

	 cout<<"*****MENU*****\n";
	 string menuStar = "*****";
	 for (int menu=50; menu > 5; menu -=5  )
	 {
		 cout<<menuStar<<endl;
	 }
	 cout<<"\n";
	 cout<<CLASS1<<"-- to display you first class scores\n";
	 cout<<CLASS2<<"-- to display you second class scores\n";
	 cout<<CLASS3<<"-- to display you third class scores\n";
	 cout<<CLASS4<<"-- to display you fourth class scores\n";
	 cout<<CLASS5<<"-- to display you fifth class scores\n";
	 cout<<CLASS_ALL<<"--to display all of your class scores sorted\n";
	 cout<<EXIT<<"--to exit the program\n\n"; 
	 cout<"Please choose an option from 1 to 7: ";
	 do{
	 cin>>choice;
	if (choice == 7)
		{
		system("pause");
		exit (0);
		 }
		 }while (choice ==7);
 }


 void goSort(int newGrade[], const int NEW_GRADE )
 {
	 
	 for (int k = 1; k < NEW_GRADE; k++)
		 for (int i = 0; i <new_grade -1="" -="" mode="hold" />			 if (newGrade[i] > newGrade[i +1]){
				 int temp = newGrade[i];
				 newGrade[i] = newGrade[i + 1];
				 newGrade[i + 1] = temp;
			 } 
	for (int count = 0; count < NEW_GRADE; count++)
	{
		cout<<"Grade "<<count<<"  :"<<newGrade[count]<<"\n";
	}


 }
Posted
Updated 8-Nov-13 7:57am
v3
Comments
Sergey Alexandrovich Kryukov 8-Nov-13 13:37pm    
Look at your code. Repeated #include, and so on. The code is not actually shown. You need to strengthen you HTML skills and put it right. And sandwich the code in <pre lang="c++"> ... your code... </pre>.
—SA
therainking78 8-Nov-13 23:32pm    
<pre> ? It has some interesting properties. I never used though was deprecated with HTML 4. I didn't learn to create web apps with it. I started with XHTML transitional/strict never learned it. I try to stay away from anything that isn't supported in HTML 5. For the forum it's good to know otherwise I wouldn't want to get in the habit of using old tags.
Aescleal 8-Nov-13 16:29pm    
You might like to just present the bit of code you're having trouble with rather than giving us a shed load of loops with more nesting than an orgy of randy seagulls.
therainking78 8-Nov-13 23:40pm    
"more nesting than an orgy of randy seagulls." - funny but a disturbing visual. Point taken though.

1 solution

If your problem is getting the names for the classes into the array of strings then use std::getline - the free function, not the member of I stream.

Oh, try and factor out all the repeated code. It makes reading what you've written harder than it needs to be.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900