Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

URGENT!!! Need help with this program- This is what I got, but still have too ma

ID: 3783898 • Letter: U

Question

URGENT!!!    Need help with this program-

This is what I got, but still have too many errors!!!

#include<iostream>
5 #include<iomanip>
6 #include<cstring>
7 #include<cctype>
8 #include<cstdlib>
9
10 using namespace std;
11 #define MAX 10
12
13 bool isPositive(int count){
14     if (count> 0 && count<= MAX)
15        return (true);
16 }
17
18 int inputTestsScores(int* tmp){
19
20     for(int i=0; i<MAX; i++){
21     cout << "Enter the test score: " << endl;
22     cin >> tmp[i];
23
24         while(tmp < 0 || tmp > 100){
25         cout << "Invalid test score " << endl;
26
27         }
28     }
29    }
30
31 int* allocate(int count) {
32     int* tmp = NULL;
33
34     if (count > 0){
35         try{
36             tmp = new int[count];
37         }catch(bad_alloc){
38             cout << "Bad allocation ";
39         }
40     }
41     return(tmp);
42 }
43
44 float calcTestAvg(const int *tests, int count){
45    int total = 0;
46     for(int i=0; i<MAX; i++){
47         total += tests[i];

48
49       float avg = ((float)total/count);
50
51    }
52 }
53 int displayTestResults(const int *tests, int count, float avg){
54     cout << inputTestsScores << endl;
55     cout << "Average Test Score: " << setprecision(2) << fixed << avg << end    l;
56 }
57
58 void deallocate(int* &tests){
59     if(tests!=NULL){
60         delete[] tests;
61         tests=NULL;
62     }
63     return;
64 }
65
66 char convertToLowerCase(char response, char strlen(response)){
67
68     for(int i=0; i<MAX; i++){
69     strlen[i] = toLower(strlen[i]);
70     }
71 }
72
73 int main() {
74     int count, *tests = NULL;
75     float avg=0;
76     char response[MAX];
77     do {
78         do {
79             cout << "How many tests scores do you want to enter? " ;
80             cin >> count;
81         }while (!isPositive(count)); // need to define
82         tests = allocate(count); // need to define
83         if(tests!=NULL) {
84             inputTestsScores(tests,count); //need to define
85             avg == calcTestAvg(tests, count); //need to define
86             displayTestResults(tests, count, avg);// need to define
87             deallocate(tests); // need to define
88         } else {
89             cout << "bad allocation ";
90             exit(1);
91         }
92         cout << "Enter new series of test scores? (yes/no) ";

93         cin.ignore(256, ' ');
94         cin.getline(response, MAX);
95         convertToLowerCase(response, strlen(response)); // need to define
96         }while(!strcmp(response, "yes"));
97 }
98
99
100
101

Explanation / Answer

//No ERROR Program

#include<iostream>
#include<iomanip>
#include<cstring>
#include<cctype>
#include<cstdlib>
using namespace std;
#define MAX 10
bool isPositive(int count){
if (count> 0 && count<= MAX)
return (true);
else
return false;
}

int* inputTestsScores(int* tmp,int count)
{

for(int i=0; i<count; i++)
{
cout << "Enter the test score: " << endl;
cin >> tmp[i];
if(tmp[i] < 0 || tmp[i] > 100)
{
cout << "Invalid test score " << endl;
i--;
}
}
return (tmp);
}

int* allocate(int count) {
int* tmp = NULL;

if (count > 0){
try{
tmp = new int[count];
}catch(bad_alloc){
cout << "Bad allocation ";
}
}
return(tmp);
}

float calcTestAvg(int *tests, int count){
int total = 0;
float avg=0;
for(int i=0; i<count; i++)
{
total += tests[i];
avg = ((float)total/count);
}
return avg;
}
void displayTestResults(const int *tests, int count, float avg){
for (int i=0;i<count;i++)
cout << tests[i] << endl;
cout << "Average Test Score: " << setprecision(2) << fixed << avg << endl;
}

void deallocate(int* &tests)
{
if(tests!=NULL)
{
delete[] tests;
tests=NULL;
}

}

char* convertToLowerCase(char* response, int len){
char data[MAX];
for(int i=0; i<len; i++){
data[i] = int(response[i])+32;
}
return data;
}

int main() {
   int count, *tests = NULL;
    float avg=0;
    char response[MAX];
    do
    {
do
{
cout << "How many tests scores do you want to enter? " ;
cin >> count;
}while (!isPositive(count)); // need to define
tests = allocate(count); // need to define
if(tests!=NULL)
{
inputTestsScores(tests,count); //need to define
avg = calcTestAvg(tests,count); //need to define
displayTestResults(tests,count,avg);// need to define
deallocate(tests); // need to define
}
else
{
cout << "bad allocation ";
exit(1);
}
cout << "Enter new series of test scores? (yes/no) ";
cin.ignore(256, ' ');
cin.getline(response, MAX);
convertToLowerCase(response, strlen(response)); // need to define
}while(!strcmp(response, "yes"));
}