Question

In: Computer Science

Please in C++ thank you! Please also include the screenshot of the output. I have included...

Please in C++ thank you! Please also include the screenshot of the output. I have included everything that's needed for this. Pls and thank you!

Write a simple class and use it in a vector.

Begin by writing a Student class. The public section has the following methods:

Student::Student()

Constructor. Initializes all data elements: name to empty string(s), numeric variables to 0.

bool Student::ReadData(istream& in)

Data input. The istream should already be open. Reads the following data, in this order:

• First name (a string, 1 word)

• Last name (also a string, also 1 word)

• 5 quiz scores (integers, range 0-20)

• 3 test scores (integers, range 0-100)

Assumes that all data is separated by whitespace. The method returns true if reading all data was successful, otherwise returns false. Does not need to validate or range-check data; if one of the quiz or test scores is out of range, just keep going.

bool Student::WriteData(ostream& out) const

Output function. Writes data in the following format. Each student’s data is on one line.

• First name (left justified, 20 characters)

• Last name (left justified, 20 characters) • 5 quiz scores (each right justified in a field 4 characters wide)

• 3 test scores (each right justified in a field 5 characters wide)

• new-line character ‘\n’ or use of endl in output function

Note that this is a const method; it should not modify any of the object’s data. Returns true if the attempt to send the data to the stream was successful, false otherwise.

string Student::GetFirstName() const;

string Student::GetLastName() const;

Accessor methods, also known as ‘getters.’ Returns data from inside the function.

float Student::CourseAverage() const

Returns the student’s weighted average as a percentage (float in range 0-100). The quiz scores are averaged together (20-point scale) and are 35% of the course grade. The test are averaged together and are 65% of the course grade. This does not modify any of the object’s data.

bool Student::DisplayCourseAverage(ostream& out) const Prints the student’s course average to the provided output stream, rounded to 3 decimal places. Returns true if the attempt was successful, false otherwise.

string Student::LetterGrade() const Returns a string with the student’s letter grade, using the same grading scale as this course. The class should assume that any input or output streams passed to public methods are already open.

The main program is quite simple. You are provided a data file with data for some number of students. Read the data into a vector. (Hint: Declare one student. Read that student’s data, then add it to the vector. Repeat.) It should then print a roster, showing the name, course average to 3 decimal places, and letter grade for each student in the course. This list should be sorted by student name (sort by last name, break ties using first name; display in usual first-name last-name order).

Here is the input.txt

23
MIRANDA BOONE 17 17 13 17 20 86 91 71
LARRY MARSH 16 11 20 15 11 78 82 96
JANIE FOWLER 18 18 19 18 20 80 90 69
ALBERTO GILBERT 15 20 18 17 19 51 76 99
SUE LEONARD 12 15 12 18 17 85 77 100
CARL BALLARD 16 12 16 16 20 65 80 92
LESLIE PEREZ 13 18 17 12 20 81 81 96
MORRIS NEWTON 20 19 19 20 16 75 80 66
BRANDI LAMB 19 17 20 12 16 97 67 65
HERBERT HARVEY 20 16 11 14 12 80 100 80
RUDOLPH FISHER 17 18 20 18 18 82 68 77
LAURIE PHELPS 18 11 13 16 15 90 93 76
PHILIP ZIMMERMAN 17 13 18 16 18 79 78 64
BRAD HAYES 17 20 13 11 20 81 92 87
BELINDA JACKSON 18 10 16 18 16 59 76 87
JESSIE MORAN 16 14 13 19 19 78 79 66
BRIDGET KELLER 19 14 15 20 20 90 66 66
CHAD RODRIGUEZ 15 16 20 18 18 86 71 79
KENNETH KELLY 11 19 17 19 18 76 75 67
CASSANDRA MASON 14 20 18 20 17 85 76 100
RANDY JACKSON 18 19 15 19 17 67 61 65
GARRY CLAYTON 10 16 18 14 19 86 85 84
NICK FLOYD 18 13 20 17 16 79 76 81

Solutions

Expert Solution

Program

#include<iostream>
#include<fstream>
#include<vector>
#include<iomanip>
using namespace std;

//Student class
class Student
{
private:
//private data members
string firstName;
string lastName;
int quizScore[5];
int examScore[3];
public:
//public functions
Student();
bool ReadData(istream& in);
bool WriteData(ostream& out) const;
string GetFirstName() const;
string GetLastName() const;
float CourseAverage() const;
bool DisplayCourseAverage(ostream& out) const;
string LetterGrade() const;
};
//constructor
Student::Student()
{
firstName = "";
lastName = "";
for(int i=0; i<5; i++)
quizScore[i] = 0;
for(int i=0; i<3; i++)
examScore[i] = 0;
}
//function to read the data
bool Student::ReadData(istream& in)
{
in>>firstName;
if(in.fail())
return false;
in>>lastName;
if(in.fail())
return false;
for(int i=0; i<5; i++){
in>>quizScore[i];
if(in.fail())
return false;
}
for(int i=0; i<3; i++){
in>>examScore[i];
if(in.fail())
return false;
}
return true;
}
//function to write the data
bool Student::WriteData(ostream& out) const
{
out<<left<<setw(20)<<firstName;
if(out.fail())
return false;
out<<left<<setw(20)<<lastName;
for(int i=0; i<5; i++)
out<<right<<setw(4)<<quizScore[i];
for(int i=0; i<3; i++)
out<<right<<setw(5)<<examScore[i];
out<<endl;
return true;
}
//function to return the firstName
string Student::GetFirstName() const
{
return firstName;
}
//function to return the lastName
string Student::GetLastName() const
{
return lastName;
}
//function to calculate course average
float Student::CourseAverage() const
{
float avg1, avg2, sum = 0;
for(int i=0; i<5; i++)
sum += quizScore[i];
avg1 = sum/5;
sum = 0;
for(int i=0; i<3; i++)
sum += examScore[i];
avg2 = sum/3;
return (avg1*35/20 + avg2*65/100);
}
//function to display course average
bool Student::DisplayCourseAverage(ostream& out) const
{
out<<fixed<<setprecision(3);
out<<left<<setw(20)<<CourseAverage();
if(out.fail())
return false;
return true;
}
//function to return the letter grade
string Student::LetterGrade() const
{
float ca = CourseAverage();
if (ca >= 93 && ca <= 100) return "A";
if (ca >= 90) return "A-";
if (ca >= 87) return "B+";
if (ca >= 83) return "B";
if (ca >= 80) return "B-";
if (ca >= 77) return "C+";
if (ca >= 73) return "C";
if (ca >= 70) return "C-";
if (ca >= 67) return "D+";
if (ca >= 60) return "D";
return "F";
}

//function to sort the vector
void sorting(vector<Student> &sv)
{
//sort the vector according to the last name
for(int i=0; i<sv.size()-1; i++){
for(int j=i+1; j<sv.size(); j++){
if(sv[i].GetLastName() > sv[j].GetLastName() ||
(sv[i].GetLastName() == sv[j].GetLastName() &&
sv[i].GetFirstName() > sv[j].GetFirstName())){
Student stu = sv[i];
sv[i] = sv[j];
sv[j] = stu;
}
}
}
}

//main function
int main()
{
ifstream fin;
//open the file
fin.open("Program4Data.txt");
//check if file exist
if(!fin.is_open())
{
cout<<"File not exist!"<<endl;
return 1;
}
//declare vector of Student
vector<Student> sv;

Student stu;
//read data from the file and add to the vector
while(stu.ReadData(fin))
{
sv.push_back(stu);
}

//sort the vector
sorting(sv);

//display the roaster
for(int i=0; i<sv.size(); i++)
{
cout<<left<<setw(20)<<sv[i].GetFirstName();
cout<<left<<setw(20)<<sv[i].GetLastName();
cout<<left<<setw(20)<<sv[i].CourseAverage();
cout<<sv[i].LetterGrade()<<endl;
}

return 0;
}

Output:

Solving your question and helping you to well understand it is my focus. So if you face any difficulties regarding this please let me know through the comments. I will try my best to assist you.
Thank you.


Related Solutions

I want to understand how this can be solved in c++. Please send a screenshot also...
I want to understand how this can be solved in c++. Please send a screenshot also with your code so I can see how it is supposed to be formatted or indented. Instructions: Your program will read in a file of commands. There are three types of commands: Warrior creates a new warrior with the specified name and strength. Battle causes a battle to occur between two warriors. Status lists all warriors, alive or dead, and their strengths. A sample...
PLEASE do the following problem in C++ with the screenshot of the output. THANKS! Assuming that...
PLEASE do the following problem in C++ with the screenshot of the output. THANKS! Assuming that a text file named FIRST.TXT contains some text written into it, write a class and a method named vowelwords(), that reads the file FIRST.TXT and creates a new file named SECOND.TXT, to contain only those words from the file FIRST.TXT which start with a lowercase vowel (i.e., with 'a', 'e', 'i', 'o', 'u'). For example, if the file FIRST.TXT contains Carry umbrella and overcoat...
3. Add mutex locks to tprog2.c to achieve synchronization, and screenshot the output tprog2.c #include <stdio.h>...
3. Add mutex locks to tprog2.c to achieve synchronization, and screenshot the output tprog2.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> void* print_i(void *ptr) { printf("1: I am \n"); sleep(1); printf("in i\n"); } void* print_j(void *ptr) { printf("2: I am \n"); sleep(1); printf("in j\n"); } int main() { pthread_t t1,t2; int rc1 = pthread_create(&t1, NULL, print_i, NULL); int rc2 = pthread_create(&t2, NULL, print_j, NULL); exit(0); }
using C thank you Must submit as MS Word file with a screenshot of the 3...
using C thank you Must submit as MS Word file with a screenshot of the 3 outputs. Run your program 3 times. the output must be in a screenshot not typed for the each time you run the program. thank you Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will...
If you have a chance please answer as many as possible, thank you and I really...
If you have a chance please answer as many as possible, thank you and I really appreciate your help experts! Question 1 2 pts A consumer analyst reports that the mean life of a certain type of alkaline battery is no more than 63 months. Write the null and alternative hypotheses and note which is the claim. Ho: μ ≤ 63 (claim), Ha: μ > 63 Ho: μ = 63 (claim), Ha: μ ≥ 63 Ho: μ > 63 (claim),...
If you have a chance please answer as many as possible, thank you and I really...
If you have a chance please answer as many as possible, thank you and I really appreciate your help experts! Question 6 2 pts A scientist claims that the mean gestation period for a fox is 51.5 weeks. If a hypothesis test is performed that rejects the null hypothesis, how would this decision be interpreted? The evidence indicates that the gestation period is less than 51.5 weeks There is enough evidence to support the scientist’s claim that the gestation period...
If you have a chance please answer as many as possible, thank you and I really...
If you have a chance please answer as many as possible, thank you and I really appreciate your help experts! Question 16 2 pts In a hypothesis test, the claim is μ≤28 while the sample of 29 has a mean of 41 and a standard deviation of 5.9. In this hypothesis test, would a z test statistic be used or a t test statistic and why? t test statistic would be used as the sample size is less than 30...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
Please complete both questions in MASM. Explain code clearly, thank you. Please screenshot memory outputs. Symbolic...
Please complete both questions in MASM. Explain code clearly, thank you. Please screenshot memory outputs. Symbolic Text Constants Write a program that defines symbolic names for several string literals (characters between quotes). Use each symbolic name in a variable definition. Use this code to get started: ; Symbolic Text Constants Comment ! Description: Write a program that defines symbolic names for several string literals (characters between quotes). Use each symbolic name in a variable definition. ! .386 .model flat,stdcall .stack...
program runs but does not compute the average. Here is what I have. Thank you #include...
program runs but does not compute the average. Here is what I have. Thank you #include <iostream> #include<iomanip> #include"Average.h" using namespace std; int main() {    cout<<"Enter 3 integers, seperated by spaces, on a single line: ";    int number1, number2, number3;    cin>>number1>>number2>>number3;    int average;    double avg; //   average = computeAverage(number1, number2, number3);    cout<<"Average of "<<number1<<" and "<<number2 <<" and "<<number3 <<" is "    <<average<<endl;          cout<<"Enter 2 integers, seperated by a space,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT