Question

In: Computer Science

Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with...

Project 1 - Arrays - Grader

The purpose of this assignment is to practice dealing with arrays and array parameters. Arrays are neither classes nor objects. As a result, they have their own way of being passed as a parameter and they also do not support the dot operator ( .), so you cannot determine how full they are. This results in some pain and suffering when coding with arrays. It is this awareness that I am trying to get across to you in this homework assignment.

Grader

The Grader class is keeping track of a set of eexam scores. Scores can be added one at a time thru calls to addScore(...)or it can add a set of scores thru calls to addScores(...). Once scores have been collected, the Grader class can find the best and worst scores it has seen so far thru calls to findBiggest()and findSmallest().

  • findBiggest()returns the value of the largest score in the grader. If no scores are present, return -1.
  • findSmallest()returns the value of the smallest score in the grader. If no scores are present, return -1.

Both of these methods are read-only operations, so you won’t be able to change or update anything inside the Grader instance object. Processing arrays lead to lots of loops and that is what will be necessary in these methods. As for the MAX_SIZEconstant, I would recommend you just set it to a very large number (say 100…) and move on.

You will notice also that the class Grader has an integer counter named valuesSeenSoFar. This counter is meant to tell you how full the array actually is. Since an array is not a class, you can’t ask the my_Valuesarray any questions. This counter needs to be maintained (incremented and decremented) by your Grader class code, as driver code fills and empties the array.

Following the class diagrams shown below, implement the Grader class. Embed your class in a suitable test program that proves your calculations are correct. You may choose to create any number of additional methods, but you are required to implement all of the public methods shown below. You are free to ignore the private parts of the class I suggest below.

I need in three file:

grade.cpp

grade.h

main.cpp

Implementation Details - Grader

Grader();

void addScore(int score);
void addScores(int scores[], int size);
void clear();

int findBiggest() const;
int findSmallest() const;

int my_Values[MAXSIZE];
int my_valuesSeenSoFar;

Sample Driver Code

Grader g;
int d[5]= {99,70,85,93,84};
int e[4]= {100,81,60,91};

g.addScore(75);
g.addScore(82);
g.addScores(d, 5);

cout << "Best Score = " << g.findBiggest() <<
endl;
/// should give value 99
cout << "Worst Score = " << g.findSmallest() <<
endl;
/// should give value 70
g.clear();

g.addScore(50);
g.addScore(74);
g.addScores(e, 4);

cout << "Best Score = " << g.findBiggest() <<
endl;
/// should give value 100
cout << "Worst Score = " << g.findSmallest() <<
endl;
/// should give value 50

Sample Output

Best Score = 99
Worst Score = 70
Best Score = 100
Worst Score = 50

Solutions

Expert Solution

Code:-

/// main.cpp ///

#include<iostream>
#include"grade.cpp"
using namespace std;
int main()
{
Grader g;
int d[5]= {99,70,85,93,84};
int e[4]= {100,81,60,91};
g.addScore(75);
g.addScore(82);
g.addScores(d,5);
cout << "Best Score = " << g.findBiggest() << endl;
cout << "Worst Score = " << g.findSmallest() << endl;
g.clear();
g.addScore(50);
g.addScore(74);
g.addScores(e, 4);
cout << "Best Score = " << g.findBiggest() << endl;
cout << "Worst Score = " << g.findSmallest() << endl;
return 0;
}

/// grade.cpp ///

#include"grade.h"
using namespace std;
Grader::Grader()
{
my_valuesSeenSoFar=-1;
}
void Grader::addScore(int score)
{
if(my_valuesSeenSoFar<100)
{
my_valuesSeenSoFar++;
my_Values[my_valuesSeenSoFar]=score;
}
}
void Grader::addScores(int scores[], int size)
{
int i=0;
while(my_valuesSeenSoFar<100 && i<size)
{
my_valuesSeenSoFar++;
my_Values[my_valuesSeenSoFar]=scores[i];
i++;
}
}
void Grader::clear()
{
my_valuesSeenSoFar=-1;
}
int Grader::findSmallest() const
{
if(my_valuesSeenSoFar==-1)
return -1;
int min_value=my_Values[0];
for(int i=0;i<=my_valuesSeenSoFar;i++)
{
if(min_value>my_Values[i])
{
min_value=my_Values[i];
}
}
return min_value;
}
int Grader::findBiggest() const
{
if(my_valuesSeenSoFar==-1)
return -1;
int max_value=my_Values[0];
for(int i=0;i<=my_valuesSeenSoFar;i++)
{
if(max_value<my_Values[i])
{
max_value=my_Values[i];
}
}
return max_value;
}

/// grade.h ///

#define MAXSIZE 100
class Grader
{
public:
Grader();
void addScore(int score);
void addScores(int scores[], int size);
void clear();
int findBiggest() const;
int findSmallest() const;
int my_Values[MAXSIZE];
int my_valuesSeenSoFar;
};

Code Screenshots:-

Output:-

Please UPVOTE thank you...!!!


Related Solutions

Project Assignment The purpose of this assignment is for you to gain practice in applying the...
Project Assignment The purpose of this assignment is for you to gain practice in applying the concepts and techniques we learned in class. In order to complete the assignment, please do the following: 1. find or create a data set containing values of at least one interval or ratio variable for at least one-hundred cases (n >= 100); 1 2. provide basic descriptive statistics to summarize the central tendency and variability of the data; 3. provide at least one table...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
The purpose of this C++ programming assignment is to practice using an array. This problem is...
The purpose of this C++ programming assignment is to practice using an array. This problem is selected from the online contest problem archive, which is used mostly by college students worldwide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest. For your convenience, I copied the description of the problem below with my note on the I/O and a sample executable. Background The world-known gangster Vito Deadstone...
The purpose of this assignment is to practice economic theories related to saving, investment, and the...
The purpose of this assignment is to practice economic theories related to saving, investment, and the financial system Are Future Budget Deficits a Threat to the​ Economy? Congress gives the Congressional Budget Office​ (CBO) the responsibility of estimating the effects of federal spending and taxing policies on the economy. An Associated Press news story on a CBO report noted that federal budget deficits in the United States were likely to increase in future years. According to the​ CBO, these higher...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
The purpose of this assignment is to practice working with marketing research data, searching for patterns...
The purpose of this assignment is to practice working with marketing research data, searching for patterns in the numbers that might lead you to a new understanding about consumers, their behaviors or their preferences. Download the McSandwich Excel spreadsheet that lists the responses given by 50 customers of the fast food restaurant. The customers were asked questions about the food (quality & variety), service (friendly, fast & competent), pricing, the overall experience (recommend to a friend, general satisfaction), and some...
Objective: The purpose of this programming assignment is to practice using STL containers. This problem is...
Objective: The purpose of this programming assignment is to practice using STL containers. This problem is selected from the online contest problem archive (Links to an external site.), which is used mostly by college students world wide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest (Links to an external site.). For your convenience, I copied the description of the problem below with my note on the...
The purpose of this project is to practice the pthread built in functions. The following c...
The purpose of this project is to practice the pthread built in functions. The following c program is a simple program to make a matrix of integers and print it. //File name: a.c #include <stdio.h> #include <time.h> #include <stdlib.h> int** a; int main(){ time_t t; int m, n, i, j;       //m is the numbers of rows and n is the number of columns. printf("Enter the number of rows, and columns: "); scanf("%d%d", &m, &n); printf("%d, %d\n", m, n); srand((unsigned) time(&t));...
Program in Java using Inheritence The purpose of this assignment is to practice OOP programming covering...
Program in Java using Inheritence The purpose of this assignment is to practice OOP programming covering Inheritance. Core Level Requirements (up to 6 marks) The scenario for this assignment is to design an online shopping system for a local supermarket (e.g., Europa Foods Supermarket or Wang Long Oriental Supermarket). The assignment is mostly concentrated on the product registration system. Design and draw a UML diagram, and write the code for the following classes: The first product category is a fresh...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT