Question

This is a standard C++ programming assignment using a command line g++ compiler or the embedded...

This is a standard C++ programming assignment using a command line g++ compiler or the embedded one in zyBooks. No GUI forms and no Visual Studio. No external files and no databases are used.

There is only one object-oriented program to complete in this assignment. All code should be saved in a file named ExamScoresUpdate.cpp, which is the only file to submit for grading. No .h files used.

The .cpp file contains main() and two classes, ExamScores and DataCollector. There is no any relationships, including inheritance between these two classes. Their definition and usage are described later starting from item 10.

If you submit a .cpp file which cannot compile by g++ due to syntax errors, you will receive no more than 20% or 10 points for this assignment.

This program, i.e., main(), first lets user enter two sets of scores, set1 and set2, one set a time and one score per line until -999 is entered. Scores are all integers, positive or negative, and can be zero. Each set may contain no score or any number of scores, and they may contain same or different numbers of scores.

Without including exception handling, which will be discussed in Chapter 9, this program assumes user only enters integer scores or 0 or -999. Therefore, input data validation is not necessary.

After the first two sets of scores are entered, the program updates every score of set1 by adding the corresponding score of set2 and display the result. For example, if set1 and set2 each contains three scores, say, { 70, 90, 50 } and { 2, -1, 100 }, respectively, the update (i.e., set1 + set2) changes set1 to { 72, 89, 150 }. See the upper half of the left-hand-side figure below.

It then lets user enter the 3rd set of scores, set3, and uses it to update scores of set1 again and display the result. For example, if set3 is { 1, 0, 33 }, the update (i.e., set1 + set3) changes the above set1 to { 73, 89, 183 }. See the lower half of the left-hand-side figure below.

An important rule for each update is both sets must contain equal number of of scores. If not, an error message is displayed as "<ERROR> Cannot update--score sets have unequal sizes!" See the the upper half of the right-hand-side figure below, where an error occurs because set2 has only one score while set1 has three.

Since we want this to be an object-oriented program with classes and main() and we expect no stand alone functions to be included. Therefore, to support the process of main(), two classes are required, which are ExamScores and DataCollector.

The ExamScores class defines only one private data member, which is a vector of integers. When scores of set1 and set3 are entered, they are supposed to be stored in this data member of two ExamScores objects separately. However, scores of set2 are held directly in a vector of integers in main().

The ExamScores class defines no constructors but five public member functions:

GetScores: it returns the private data member of ExamScores, which is a vector of integers.

EnterScore: it takes an input parameter of integer and adds it to the private data member of ExamScores with no return value.

Update: it takes an input parameter of a vector of integers and, if the vector of integers of the private data member of ExamScores and the input vector have identical size, it adds each integer of the input vector to the integer at the same position of the private data member of ExamScores. If both vectors have unequal sizes, it displays "<ERROR> Cannot update--score sets have unequal sizes!" (see the right-hand-side figure below). It has no return value.

Update: an overloading function of the above Update. It uses an input parameter of an ExamScores object to perform the same as the above Update.

Display: it displays vector of integers of the private data member of ExamScores, one number per line. The display begins and ends with a line of dashes like '---------' and a simple header of 'Scores:' is printed before the first score.

For grading purpose, no other member functions should be included.

The  DataCollector class is defined to facilitate user interaction for data input and store them in an ExamScores object or a vector. It has no data members at all but two public overloading member functions called AskUser(), one returns an ExamScores object and the other returns a vector of integers. Because different return types cannot make overloading functions, these two AskUser() must use either different types or different numbers of input parameters. This is a part intended for your own design. Whichever way you choose to make them overloaded, the input parameter(s) is supposed to be used to display the header line like "Exam scores of set 1" or "Exam scores of set 2". After this line, AskUser() starts a loop to prompt user "Enter an integer score or '-99' to end:" to collect score input and store them in an ExamScores object or a vector of integers. The loop ends when user enters -999 and AskUser() returns its ExamScores object or vector of integers.

As a part of requirements of the main(), input of set1 and set3 must use AskUser() which returns an ExamScores object, and input of set2 must use the other AskUser() to return a vector.

To help you to design and test this program, a .exe file for Windows is attached below with two samples of screenshot. You can download the .exe to your Windows and double click it to test run the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream.h>

#include<conio.h>

class ExamScores

{

int v[20];

public:

int c;

ExamScores()

{

c=0;

}

int * GetScores()

{

return v;

}

void Display()

{

cout<<"\n Scores";

cout<<"\n ------";

for(int i=0;i<c-1;++i)

{

cout<<"\n"<<v[i];

}

cout<<"\n---End Score----\n";

}

void EnterScore(int x)

{

v[c++]=x;

}

void Update(int b[],int n)

{

if(n!=c)

{

cout<<"\n Error Occured Two Sets are not of Same Size\n";

return;

}

for(int i=0;i<c;++i)

v[i]=v[i]+b[i];

}

void Update(ExamScores obj)

{

if(c!=obj.c)

{

cout<<"\n Error Occured Two Sets are not of Same Size\n";

return;

}

for(int i=0;i<c;++i)

v[i]=v[i]+obj.v[i];

}

};

class DataCollector

{

public:

int AskUser(int a[])

{

int c=0;

int n=0;

while(n!=-999)

{

cout<<"\n Enter integer score or -999 to end : ";

cin>>n;

a[c++]=n;

}

return c;

}

ExamScores AskUser()

{

ExamScores T;

int n=0;

while(n!=-999)

{

cout<<"\n Enter integer score or -999 to end : ";

cin>>n;

T.EnterScore(n);

}

return T;

}

};

void main()

{

ExamScores E1,E2;

DataCollector D;

clrscr();

int b[20];

cout<<"\n Enter Data for Set-1\n";

E1=D.AskUser();

cout<<"\n Enter Data for Set-3\n";

E2=D.AskUser();

cout<<"\n Enter Data for Set-2 \n";

int count=D.AskUser(b);

cout<<"\n SET1 + SET2 \n";

E1.Update(b,count);

E1.Display();

cout<<"\n SET1 +SET2 + SET3 ";

E1.Update(E2);

E1.Display();

getch();

}

Add a comment
Know the answer?
Add Answer to:
This is a standard C++ programming assignment using a command line g++ compiler or the embedded...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having trouble with my C++ program.... Directions: In this lab assignment, you are to...

    I am having trouble with my C++ program.... Directions: In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node), but it need not be sorted. The IntegerSet class should have two data fields: the cardinality (size) of the set, and the head reference to the...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • get names of input and output files from command line (NOT from user input)

     2.12 LAB 2.3: File I/O - CSV update This program shouldget names of input and output files from command line (NOT from user input)read in integers from a csv (comma-separated values) file into a vectorcompute the integer average of all of the valuesconvert each value in the vector to the difference between the original value and the averagewrite the new values into a csv file

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • Please answer this question in C++. Also, please write it with 'using namespace std' because the other ways some of you do it is confusing. Class Exercise Write a program that does the follow...

    Please answer this question in C++. Also, please write it with 'using namespace std' because the other ways some of you do it is confusing. Class Exercise Write a program that does the following: 1. Defines a class named Data that has the following members a. A vector of integers entitled numbers (Private) b. Methods (Functions) (Public): i. Display_Menu Prompts the user to choose one of the following 0. Quit 1. Input Numbers 2. Display Numbers 3. Search Numbers 4....

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • Submission Instruction Complete the following C++ programs. The assignment contains only one file with all different...

    Submission Instruction Complete the following C++ programs. The assignment contains only one file with all different class and functions from problem 1. The main function calls different functions as instructed in the problem description. Submit the CPP file during submission Problem 1. Define a class for a type called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator (one for each data). Also...

  • in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file...

    in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try it out on your own! You're to write a program that will prompt the user if he/she would like to read ints from a file (and have them displayed to stdout) or write ints to a file for safekeeping. If the user wishes to save a set of numbers, then the file nums.txt is opened...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT