useing a function to match arrays

The program i'm writing needs an array of string objects to hold five names, an array of the five letter grades, and five arrays of four 2-d arrays for each student's test scores. the scores are then averaged. Function"matchNameToGrade " is supposed to...well.. match letergrades Array to a subset in the testscores Array. ei: "if the score is 90 the letter is A." is this the correct way to do this?

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  #include <iostream>
#include <iomanip>
using namespace std;

char matchGradesToNameFunc(char, double);


int main() {
 int name; 
  char letterGradesArray[5]={'A','B','C','D','F'};
string studentNameArray[4];
  double testScores[4];
 
double testAverage[4];
{
  for (int i=0; i<5; i++)
  {
    cout << "\nEnter " << (i) << " student "<< " name ";
    cin >> studentNameArray[i];
  }
  }
//double matchGradeToNameFunc(char letterGradesArray);
  for (int j=0;j<5; j++)
  {
    cout << "\nEnter " <<" student "<<j<< " score.";
    cin >> testScores[j];
  }
  
     
     
      

  return 0;
}   
double matchGradeToNameFunc(char letterGradesArray, double testScores)
{
if ( letterGradesArray>=90)
{
double testScores[j]=lettergradesArray[0]
}

  
}


return letterGradesArray; 
} 
// while (testScores <0)
//       {
//         cout << "\nTest scoresub should be between 0 and 100" << endl;
//         cout << "Enter test scoresub: ";
//         cin >> testScores[i][j];
//       }
//     }
//    }
  

 
  //   for (int j=0;j<4;j++)
  //   testAverage[i] += testScores[i][j];
  //   testAverage[i] /= 4;
  //   gradesArray[i] = letterGradesArray[testAverage[i]];
  // cout << "\nStudent Name\tAverage Scoresub\tLetter Grade" << endl;
  // for (int i=0;i<5;i++)
  // {
    

  //   cout << studentNameArray [i] << "\t\t" << setprecision(2) << testAverage[i] << "\t\t" << gradesArray[i] << endl;
  // }


// }
// include <iostream>
// #include <iomanip> 
// #include <string>
// using namespace std;


// void getTestScore(string[],int[],int);

// int getTotal(int [],int);

// int largestElement(int[],int);
// int smallestElement(int[], int);

// int main()
// {const int salsaTypeSub=5;
//   string namesArray[salsaTypeSub]={"Mild","Medium","Sweet","Hot","Zesty"};
//   //Array of SAles for salsa types
//   int salesArray[salsaTypeSub];
// int names[5];
// //Total number of jars sold
// int totalJarsSold;

// //subscript of most sold salsa
// int highSalesProduct;

// //subscripts of least sold salsa
// int lowSalesProduct;

// //Get number of jars sold of each type of salsa
// getTestScore(namesArray, salesArray, salsaTypeSub);

//  //get total sales  and high and low Sales Products
//  totalJarsSold=getTotal(salesArray, salsaTypeSub);
// highSalesProduct=largestElement(salesArray, salsaTypeSub);
// lowSalesProduct = smallestElement(salesArray, salsaTypeSub);

// //Display the sales report header.
// cout<< endl <<endl;
// cout <<" Salsa Sales Report \n\n";
// cout <<"Name          Jars Sold \n ";
// cout << "_________________________\n";
// //Display the name and Jars sold of each type.
// for (int salsaType =0; salsaType < salsaTypeSub; salsaType++)
// {
//   cout << setw(6)<<namesArray[salsaType]
//   <<setw(21)<< salesArray[salsaType]
//   << endl;
  
// }

// //Display total sales hightes seller and lowest seller.
// cout << "\n Total Sales:" <<setw(15)<<totalJarsSold<<endl;
// cout<< "High Seller:" << namesArray[highSalesProduct]<<endl;
// cout <<"Low Seller:" << namesArray[lowSalesProduct]<<endl; 
// return 0;}

// void  getTestScore(string names[], int salesArray[],int size)
// { 
//  { for (int type = 0; type <size; type++)
//   //Get the Nmber of jars sold.
// { cout << "How many jars of " <<names[type]
//  <<" salsa did we sell last month? \n"<<endl;
// cin.clear();
//  cin >> salesArray[type];
 

//  // Validate the input.
//  while (salesArray[type] <0)
//  {
// cout <<"Jar sold must be 0 or more. Please re-enter: ";
//  cin >>salesArray[type];
//   } 
//  }
// }
// }



// int getTotal (int array [], int size)
// {
// int total=0;
// for (int pos =0; pos<size; pos++)
// total+=array[pos];

// return total;
// }

// int largestElement (int salsa[],int size)
// {int i=0;
// for (int pos=1;pos<size;pos++)
// if (salsa[pos] > salsa[i])
// {
//   i=pos;
// }
// return i;
// }

// int smallestElement (int array[],int size)
// {int i=0;
// for (int pos=1;pos<size;pos++)
// if (array[pos] <array [i])
// {
//   i=pos;
// }
// return i;
// } 
1
2
3
4
5
6
7
8
9
10
char letter_grade(double score){
   if (score>=90) return 'A';
   if (score>=80) return 'B';
   //...
   return 'F';
}


for (int K=0; K<n; ++K)
   cout << letter_grade(test_score[K]) << ' ';
this could get you in trouble ... but the work smarter answer is something like this
string grade = "FFFFFFDCBAA";
answer = grade[avg/10]; 0 /10 = 0 -> F, 53/10 = 5 -> F, 62/10 = 6 ->D, 100/10 = 10 ->A etc
Last edited on
Topic archived. No new replies allowed.