![]() |
| | #1 |
| Registered User Join Date: Mar 2004
Posts: 15
| Code: ----------------------------
| EXAM | SCORE | GRADE |
----------------------------
| HIGH | 100 | A |
----------------------------
| AVG | 83 | B |
----------------------------
| LOW | 61 | D |
----------------------------
| 1 | 100 | A |
----------------------------
| 2 | 73 | C |
----------------------------
| 3 | 94 | A |
----------------------------
| 4 | 61 | D |
----------------------------
| 5 | 87 | B |
----------------------------
# include <iostream.h>
# include <iomanip.h>
# include <math.h>
// This program asks the user to enter a series of test scores //
// Then it will determine the highest , lowest , and average scores//
// The corresponding letter grade will be assigned to the scores//
// And finally a table of output will be displayed//
// ***** VARIABLE DECLARATIONS ******//
int promptscore (void);
void displayoutput (int[], int );
char examgrade (int);
int avggrade ( int[], int );
int highestgrade ( int [], int );
int lowestgrade (int [] , int );
void clearscreen (void);
const int maxels = 8; //maximum # of array elements
int examscore [maxels];
//****** MAIN PROGRAM BODY *************//
main ()
{
int score , i = 0;
clearscreen();
score = promptscore();
while (score = 0 && i < maxels )
{
examscore[i++] = score;
if ( i < maxels )
score = promptscore();
}
displayoutput(examscore , i);
}
//****** THIS IS THE PROMPT FOR SCORE FUNCTION******//
int promptscore(void)
{
int examscore;
cout << " enter score , enter a negative number to quit : ";
cin >> examscore;
return examscore;
// ******* THIS IS THE FUNCTION FOR HIGHEST GRADE *******//
int highestgrade ( int exam [], int nbrofexams)
{
int i , highestgrade;
highestgrade= exam[0];
for ( i = 0; i < nbrofexams; i++)
{
if (exam[i] > highestgrade)
highestgrade = exam[i];
}
}
// ********** THIS IS THE LOWEST SCORE FUNCTION ********//
int lowestgrade ( int exam [], int nbrofexams)
{
int i , lowestgrade;
lowestgrade= exam[0];
for ( i = 0; i < nbrofexams; i ++ )
{
if( exam [i] < lowestgrade)
lowestgrade = exam[i];
}
}
//*** THIS IS THE INCOMPLETE !!!!!!! AVERAGE GRADE FUNCTION *****//
float averagegrade ( int grade [] , int n )
{
int sum = 0;
for ( int i = 0 ; i < n; i ++ )
sum += grade [i];
return (sum) / n;
}
//!!!!!!!!!!!!! CHAR EXAM GRADE FUNCTION !!!!!!!!!!!!!!//
// !!!!!!!!!!!!!! CLEAR SCREEN FUNCTION !!!!!!!!!!!!!!!!!!//
void clearscreen(void)
{
cout << "\033[2j\033[h";
}
// !!!!!!!!!!!!! DISPLAY OUTPUT FUNCTION !!!!!!!!!!!!!!!!!!!!!!// |
| ysuguy is offline | |
| | #2 |
| Registered User Join Date: Mar 2003
Posts: 3,898
| What exactly do you need help with? No one here is going to your homework for you. gg |
| Codeplug is offline | |
| | #3 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,674
| What's so diificult about if ( score >= 90 ) grade = 'A'; and so on through the score ranges > while (score = 0 && i < maxels ) You don't want an assignment there. From code elsewhere, I guess you meant while (score > 0 && i < maxels ) > int i , highestgrade; Having a local var with the same name as the function is very poor style. Name shadowing (where an inner scope name hides an outer scope name) can lead to all sorts of fun. Besides, there is no return result; in these functions > void displayoutput (int[], int ); Naming parameters is a good idea - especially when you start writing code which spans many files. You also seem to have creeping indentation. The file is becoming progressively more indented as you go. |
| Salem is offline | |
| | #4 |
| Registered User Join Date: Mar 2004
Posts: 15
| you have to understand this is my first programming class , i was just asking for some help i have no idea how to go about forming the table for the output I know i can make a const char line = "-------------" to make the first line and divider lines too i guess but putting it all together is where im a little flustered |
| ysuguy is offline | |
| | #5 |
| Registered User Join Date: Mar 2004
Posts: 15
| i dont think the functions were supposed to return results , simply do the work so that it can be outputted into the final table |
| ysuguy is offline | |
| | #6 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,674
| So write some code which has a few cout statements to ouput the raw information. cout << "HIGH" << highestgrade << endl; One you've outputted all the information, then start refining the formatting by using setw() and some cout statements for the dashes. |
| Salem is offline | |
| | #7 |
| Registered User Join Date: Mar 2004
Posts: 15
| was just looking for some help finishing my last 2 functions , im not a kid im trying to learn this stuff at 28 years old and never having a c or c++ class before so cut me some slack im not asking anyone to do my homework for me i got most of it done myself |
| ysuguy is offline | |
| | #8 |
| Registered User Join Date: Mar 2004
Posts: 15
| im just having trouble putting everything together , i have most of it but just not sure how to complete it ,, i dont know its frustrating im sure youre looking at this like youre kidding right but its supposed to be an intro class and believe it or not theres 6 of us left in the class from over 20 |
| ysuguy is offline | |
| | #9 |
| Registered User Join Date: Mar 2004
Posts: 44
| it is not that tough if you think about it you put your graes in a heap and the heap is already sorted then you take all the grades in the heap and add them together then divide by how many tests there are and if you want you can use modulus to find the exact average you dont need hardly any of that stuff that you are doing now but you might have to read about heaps if you dont know |
| kwm32 is offline | |
| | #10 |
| Registered User Join Date: Mar 2004
Posts: 15
| this is the way we were supposed to do it for class , he named the functions and said do the program |
| ysuguy is offline | |
| | #11 |
| Registered User Join Date: Mar 2004
Posts: 44
| you can still use heaps just read up on them you will understand |
| kwm32 is offline | |
| | #12 |
| Registered User Join Date: Mar 2004
Posts: 15
| ok ill look it up |
| ysuguy is offline | |
| | #13 | |
| Registered User Join Date: Mar 2004
Posts: 220
| Quote:
Don't worry about it Everyone has to start somewhere, and were here to help.My FULL advice on this one, is pseudo code! Write out everything you need to do in your program, and examine how you would do it with what you know and whats required. Then start writing your functions. If you have good pseudo code everything will make sense to you. >was just looking for some help finishing my last 2 functions But, beyond that..what functions do you need help with? And what do you need them to do?
__________________ OS: Windows XP Pro CE IDE: VS .NET 2002 Preferred Language: C++. Last edited by Tronic; 03-27-2004 at 04:30 PM. | |
| Tronic is offline | |
| | #14 |
| Registered User Join Date: Mar 2004
Posts: 15
| well i guess if i sit down ill be able to figure out my output table , and for my char function i need it to assign a grade to the test % so i guess all i do is take the inputted grade and do the if ( grade > 90 ) grade = 'A' i know thats rough but the idea im worried about setting the table |
| ysuguy is offline | |
| | #15 |
| Registered User Join Date: Mar 2004
Posts: 15
| By the way salem I went to your website , and im not here trying to get people to do my homework i had 80-85% of it done myself . You have to remember this is my first class , and also that you were not born a computer genius . Im just trying to get through school while working full time to better my career . Not looking for a free ride this was my first ever post for help |
| ysuguy is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Issue with program that's calling a function and has a loop | tigerfansince84 | C++ Programming | 9 | 11-12-2008 01:38 PM |
| Need help with a program, theres something in it for you | engstudent363 | C Programming | 1 | 02-29-2008 01:41 PM |
| This is a simple program.. Help me please I think it has an error.. | lesrhac03 | C Programming | 4 | 02-21-2008 10:39 AM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |