This program I'm working is just for studying purpose's for a c++ test I'm having soon and would like some context on how to make this program by switching its style from one program with a loop to one with the use of a array and a function that can be called 5 times.
The basic premise of the question is that the program will ask for how many letter grade's (A, B, C, D, or F) do you want to enter in, but can't be above 50 (In the program below I'm aware I didn't add that in). Then the user is to enter a letter grade for each test, or in other words the grades will be read into an array which will be in use in the function. The function will be called five times, once for each letter grade, then return the total number of grades in that category. The input will include the array, number of elements in the array as well as the grade category (A, B, C, D, or F). Then the program will print the grade in the order. Heres a pic of the output http://i.imgur.com/WbY2S.png
So far into making this program, I decided to make it easier for me to make, but it's not exactly what is for making this the same output.
1st code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int choice =1;
int A=0, B=0, C=0, D=0, F=0;
int i;
while (choice != -1)
{
cout << "Press the number of the 1st grade you have and this program will keep a tally\n";
cout << "- A" << "(1)\n";
cout << "- B" << "(2)\n";
cout << "- C" << "(3)\n";
cout << "- D" << "(4)\n";
cout << "- F" << "(5)\n";
cout << "(-1 to tall the results)" << endl;
cin >> choice;
switch (choice)
{
case 1:
A++;
cout << "Is there another grade? (if yes press 1, if no press -1)\n";
cin >> choice;
break;
case 2:
B++;
break;
case 3:
C++;
break;
case 4:
D++;
break;
case 5:
F++;
break;
}
cout << "Number of A's " ;
for(i =0; i<A; i++)
{
cout << "*" ;
}
cout << endl;
cout << "Number of V's " ;
for(i =0; i<B; i++)
{
cout << "*" ;
}
cout << endl;
cout << "Number of C's " ;
for(i =0; i<C; i++)
{
cout << "*" ;
}
cout << endl;
cout << "Number of D's " ;
for(i =0; i<D; i++)
{
cout << "*" ;
}
cout << endl;
cout << "Number of F's " ;
for(i =0; i<F; i++)
{
cout << "*" ;
}
cout << endl;
}
system("pause");
return 0;
}
|
It compiles but that's not exactly what the answer should be and I know theres another way to change it.
Heres the other program(or what I have so far) of it currently
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <iomanip>
using namespace std;
char returngrade(int);
int main()
{
int numGrades=0;
int index;
char lettergrade;
// Number of letter grades
cout << "How many grades do you want the program to read it? (1-50)\n";
cin >> numGrades;
cout << "All grades must be a A, B, C, D, or F, enter a grade in\n";
cout << "for the " << numGrades << "you have\n";
for (index = 0; index < numGrades; index++)
{
cout << " Input a Grade for student #" << (index + 1);
cout << " :";
cin >> lettergrade;
}
cout << "Number of A's " ;
for (i=0; i<A; i++)
{
cout << "*";
}
cout << endl;
cout << "Number of B's " ;
for (i=0; i<B; i++)
{
cout << "*";
}
cout << endl;
cout << "Number of C's " ;
for (i=0; i<C; i++)
{
cout << "*";
}
cout << endl;
cout << "Number of D's " ;
for (i=0; i<D; i++)
{
cout << "*";
}
cout << endl;
cout << "Number of F's " ;
for (i=0; i<F; i++)
{
cout << "*";
}
cout << endl;
system("pause");
return 0;
}
char returngrade()
{
char choice;
switch (choice)
{
case 'A': cout << "A.\n";
break;
case 'B': cout << "B.\n";
break;
case 'C': cout << "C.\n";
break;
case 'D': cout << "D.\n";
break;
case 'F': cout << "F.\n";
break;
}
return choice;
}
|
As you can see, it is clearly unfinished, but it would be greatly appreciated if you can help me point out the flaws (yes I'm aware that the parameters aren't right) and right variables as well as the arrays of the problem, which I'm still trying to get.