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

// AverageGrade.cpp // // This project implements a program similar to the Movie

ID: 3780070 • Letter: #

Question

// AverageGrade.cpp
//
// This project implements a program similar to the MovieRatings project. It does not
// provide all of the required 'information' shown on the movie ratings project definition.
// It the movie ratings go from 1 to (bad to worse), but this program has grade from
// A to F (best to worse). These differences need to be taken into account when using
// this program as a reference to build the MovieRatings project.


#include "AverageGrade.h"
#include <cstring>
#include <cctype>
#include <iostream>
using namespace std;

AverageGrade::AverageGrade() // default constructor
{
className[0] = ''; // set to an empty string
Acount = Bcount = Ccount = Dcount = Fcount = 0;
classSize = 0;
}

AverageGrade::AverageGrade(char *name)
{
// strcpy (className, name); // use if strcpy is required by the compiler
strcpy_s (className, 100, name); // use if strcpy_s is required by the compiler
Acount = Bcount = Ccount = Dcount = Fcount = 0;
classSize = 0;
}

void AverageGrade::setName(char* name) // mutator - sets the className
{
// strcpy (className, name); // use if strcpy is required by the compiler
strcpy_s (className, 100, name); // use if strcpy_s is required by the compiler
}

char* AverageGrade::getName() // accessor - gets the className
{
return className;
}

void AverageGrade::countGrade (char grade)
{
switch ( toupper(grade) )
{
case 'A':
Acount++; // count the number of A's
classSize++; // count the number of students
break;
case 'B':
Bcount++; // count the number of A's
classSize++; // count the number of students
break;
case 'C':
Ccount++; // count the number of A's
classSize++; // count the number of students
break;
case 'D':
Dcount++; // count the number of A's
classSize++; // count the number of students
break;
case 'F':
Fcount++; // count the number of A's
classSize++; // count the number of students
break;
default:
cout << grade << " was an illegal input value" << endl;
}
}

double AverageGrade::getAverage()
{
return ( Acount * 4.0
+ Bcount * 3.0
+ Ccount * 2.0
+ Dcount * 1.0
+ Fcount * 0.0) / classSize;
}

-----------------------------------------------

strcpy (className, 100, name); i have error of this line

-----------------------------------------------------------------

// AverageGrade.h
// Provides a C++ class definition that will collect the number of grades
// in a classroom and determine the average grade for all students.
//
// This project implements a program similar to the MovieRatings project. It does not
// provide all of the required 'information' shown on the movie ratings project definition.
// It the movie ratings go from 1 to (bad to worse), but this program has grade from
// A to F (best to worse). These differences need to be taken into account when using
// this program as a reference to build the MovieRatings project.

#ifndef AverageGrade_h // only compile this header file one time
#define AverageGrade_h

class AverageGrade
{
private:
char className[100];
int Acount;
int Bcount;
int Ccount;
int Dcount;
int Fcount;
int classSize;
public:
AverageGrade(); // default constructor
AverageGrade(char *name); // constructor with one argument
void countGrade (char grade);
void setName(char *name); // mutator - sets the name into the object
char *getName(); // accessor - gets the name from the object
double getAverage();
};
#endif

----------------------------------------------------------------------

// C++MovieRatings.cpp : Defines the entry point for the console application.
//
// This project implements a program similar to the MovieRatings project. It does not
// provide all of the required 'information' shown on the movie ratings project definition.
// It the movie ratings go from 1 to (bad to worse), but this program has grade from
// A to F (best to worse). These differences need to be taken into account when using
// this program as a reference to build the MovieRatings project.


#include "AverageGrade.h"
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
AverageGrade CIS054; // create an object of class AverageGrade
CIS054.setName("C/C++ Programming"); // use mutator to set the class name
CIS054.countGrade('A');
CIS054.countGrade('B');
CIS054.countGrade('A');
CIS054.countGrade('C');
CIS054.countGrade('B');
CIS054.countGrade('A');
CIS054.countGrade('F');
cout << "The average score for " << CIS054.getName() << " is " << CIS054.getAverage() << endl;

AverageGrade CIS073("Visual Basic Programming"); // create an object of class AverageGrade
CIS073.countGrade('A');
CIS073.countGrade('B');
CIS073.countGrade('A');
CIS073.countGrade('C');
CIS073.countGrade('B');
CIS073.countGrade('A');
CIS073.countGrade('D');
cout << "The average score for " << CIS073.getName() << " is " << CIS073.getAverage() << endl;

//system ("PAUSE");
   return 0;
}

--------------------------------------------------------------------------

i use code;;block to build this code

Explanation / Answer


// AverageGrade.h

#ifndef AverageGrade_h // only compile this header file one time
#define AverageGrade_h
class AverageGrade
{
private:
char className[100];
int Acount;
int Bcount;
int Ccount;
int Dcount;
int Fcount;
int classSize;
public:
AverageGrade(); // default constructor
AverageGrade(char *name); // constructor with one argument
void countGrade (char grade);
void setName(char *name); // mutator - sets the name into the object
char *getName(); // accessor - gets the name from the object
double getAverage();
};
#endif

// AverageGrade.cpp

#include "AverageGrade.h"
#include <cstring>
#include <cctype>
#include <iostream>

using namespace std;
AverageGrade::AverageGrade() // default constructor
{
className[0] = ''; // set to an empty string
Acount = Bcount = Ccount = Dcount = Fcount = 0;
classSize = 0;
}
AverageGrade::AverageGrade(char *name)
{
// using strcpy as it is recognized by the c++ compiler
strcpy (className, name); // use if strcpy is required by the compiler
//strcpy_s (className, 100, name); // use if strcpy_s is required by the compiler
Acount = Bcount = Ccount = Dcount = Fcount = 0;
classSize = 0;
}
void AverageGrade::setName(char* name) // mutator - sets the className
{
// using strcpy as it is recognized by the c++ compiler
strcpy (className, name); // use if strcpy is required by the compiler
//strcpy_s (className, 100, name); // use if strcpy_s is required by the compiler
}
char* AverageGrade::getName() // accessor - gets the className
{
return className;
}
void AverageGrade::countGrade (char grade)
{
switch ( toupper(grade) )
{
case 'A':
Acount++; // count the number of A's
classSize++; // count the number of students
break;
case 'B':
Bcount++; // count the number of A's
classSize++; // count the number of students
break;
case 'C':
Ccount++; // count the number of A's
classSize++; // count the number of students
break;
case 'D':
Dcount++; // count the number of A's
classSize++; // count the number of students
break;
case 'F':
Fcount++; // count the number of A's
classSize++; // count the number of students
break;
default:
cout << grade << " was an illegal input value" << endl;
}
}
double AverageGrade::getAverage()
{
return ( Acount * 4.0+ Bcount * 3.0+ Ccount * 2.0+ Dcount * 1.0+ Fcount * 0.0) / classSize;
}

// main.cpp
#include "AverageGrade.h"
#include <iostream>
#include <string.h>

using namespace std;
int main(int argc, char* argv[])
{
AverageGrade CIS054; // create an object of class AverageGrade
CIS054.setName("C/C++ Programming"); // use mutator to set the class name
CIS054.countGrade('A');
CIS054.countGrade('B');
CIS054.countGrade('A');
CIS054.countGrade('C');
CIS054.countGrade('B');
CIS054.countGrade('A');
CIS054.countGrade('F');
cout << "The average score for " << CIS054.getName() << " is " << CIS054.getAverage() << endl;
AverageGrade CIS073("Visual Basic Programming"); // create an object of class AverageGrade
CIS073.countGrade('A');
CIS073.countGrade('B');
CIS073.countGrade('A');
CIS073.countGrade('C');
CIS073.countGrade('B');
CIS073.countGrade('A');
CIS073.countGrade('D');
cout << "The average score for " << CIS073.getName() << " is " << CIS073.getAverage() << endl;
//system ("PAUSE");
return 0;
}

/*
output:

The average score for C/C++ Programming is 2.85714
The average score for Visual Basic Programming is 3


*/