Thread: C++ question/update

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    C++ question/update

    Given the following, how do I get the program to print-off cut-off values?. For each exam, the A cut-off is 0.9* the highest score. B cut-off is 0.8 * the highest , C cut-off is 0.7* the highest value and D cut-off is 0.6 * the highest value. I want it to print-out a table with A to D cut-offs as well as cut-off totals. This makes 4 columns(1 for each exam and 1 for totals) as well as 4 rows(A to D cut-offs). I got the result, but my method involves calling the GetHighestValue(exam1Array) function 3 times, for the three dirfferent arrays and manually multipling them out. It works but it's crude. i would prefer using a function. I am just a little lost as to how to design that function. Thanks!!
    Code:
    //Sample Program 12- A non-interactive program to calculate student grades.
    //**************************************************************************************
    #include<iostream>
    #include<iomanip>
    #include<fstream>
    #include<string>
    using namespace std;
    
    const int SIZE=6;
    int GetHighValue(int array[]);
    
    int main()
    {
    	int exam1Array[SIZE];
    	int exam2Array[SIZE];
    	int exam3Array[SIZE];
    	int i=0;
    	string name;
        ifstream inFile;
    
    	inFile.open("grades.dat");
    		if(!inFile)
    		{
    			cout<<"Unable to open input file, program abnormally ended";
    			return 1;
    		}
            for(i=0; i<SIZE; i++)
    		{
             
             inFile>>name>>exam1Array[i]>>exam2Array[i]>>exam3Array[i];
    		 
    		}
    		 
    			
            GetHighValue(exam1Array);
    		cout<<"The highest for exam 1 is"<<GetHighValue(exam1Array)<<endl;
    	    GetHighValue(exam2Array);
    		cout<<"The highest for exam 2 is"<<GetHighValue(exam2Array)<<endl;
    	    GetHighValue(exam3Array);
    		cout<<"The highest for exam 3 is"<<GetHighValue(exam3Array)<<endl;
    		 
    		
    		 
             
    		 
    		 return 0;
    }
    
    
    
        int GetHighValue(/*in*/ int array[])
    			{
    				 int highScore=0;
    				 int i=0;
    
    				 for(i=0; i<SIZE; i++)
    				 {
    					 if(array[i]>highScore)
    						 highScore=array[i];
    				 }
    
    				 return highScore;
    			}
    Last edited by Salem; 08-02-2006 at 11:37 PM. Reason: Added code tags, but it's still a mess

  2. #2
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    You really should copy and paste that code between [code] tags.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You should also check out this link:
    http://cboard.cprogramming.com/annou...t.php?f=3&a=39
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    I am not asking anybody to do my homework. I was merely asking for help to do something I had ALREADY done, a different way. Since posting this, I have already finished with that stage of the design. No need to direct me to that link.....it's unecessary.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > int exam1Array[SIZE];
    > int exam2Array[SIZE];
    > int exam3Array[SIZE];
    Start with
    int examArray[3][SIZE];
    int limits[3];

    Then you can have
    Code:
    getHighValues ( /*in*/int examArray[][SIZE], /*out*/int limits[] );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by brainstormin
    I am not asking anybody to do my homework. I was merely asking for help to do something I had ALREADY done, a different way. Since posting this, I have already finished with that stage of the design. No need to direct me to that link.....it's unecessary.
    Well you should be more clear, because "I got the result, but it's crude" is often translated as "my teacher handed it back because it was wrong, now I can try again". There is more to that homework post than "Don't post your homework", it's about asking a question the right way so people don't get the wrong idea. Get it?
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed