Question

In: Computer Science

#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int QUIZSIZE = 10;
const int LABSIZE = 10;
const int PROJSIZE = 3;
const int EXAMSIZE = 3;

float getAverage(float arr[], int size)
{
float total = 0;
for (int i = 0; i < size; i++)
{
total += arr[i];
}
return total/size;
}

// the following main function do....
int main()
{
ifstream dataIn;
string headingLine;
string firstName, lastName;
float quiz[QUIZSIZE];
float lab[LABSIZE];
float project[PROJSIZE];
float midExam[EXAMSIZE];
float finalExam;
float attendance;

// open the file
dataIn.open("grade120.dat");

//exception for file open
if (dataIn.fail())
{
cout << "File open error!" << endl;
return 0;
}

// read the first two lines
for (int i = 1; i <= 2; i++)
{
getline(dataIn,headingLine);
cout << headingLine << endl;
}

while (!dataIn.eof())
{

//read student's score from the file
dataIn >> firstName;
dataIn >> lastName;

for (int i = 0; i < QUIZSIZE; i++)
{
dataIn >> quiz[i];
}
for (int i = 0; i < LABSIZE; i++)
{
dataIn >> lab[i];
}
for (int i = 0; i < PROJSIZE; i++)
{
dataIn >> project[i];
}
for (int i = 0; i < EXAMSIZE; i++)
{
dataIn >> midExam[i];
}
dataIn >> finalExam;
dataIn >> attendance;
cout << "Average quiz is " << getAverage(quiz,QUIZSIZE) << endl;
cout << "Average lab is " << getAverage(lab,LABSIZE) << endl;

// call another function to calculate the final greade letter

//write the name + letter to a file

dataIn.close();
return 0;
}

Finish the C++ program below based on

(0 <= F < 60, 60 <= D < 70, 70 <= C< 80, 80 <= B < 90, 90 <= A <= 100)

THE RULES: · You need to have a total grade >=90 and average in projects >= 90 to get an A; · You need to have a total grade >=80 and < 90, and average in projects >=80 to get a B; · You need to have a total grade is >=70 and < 80, and average in projects >=70 to get a C. Poor attendance will be penalized by up to 10% of the final total grade. The grades of all the students and attendance

penalty are stored in an external file called grade120.dat. which will be given

First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3 L4 L5 L6 L7 L8 L9 P0 P1 P2 E0 E1 E2 FI ATT

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

Kevin Smith 90 100 100 100 98 97 87 100 85 87 89 100 100 100 100 90 100 98 90 100 98 98 98 90 90 98 88 0.00

Morgan Kelly 80 100 65 67 69 71 100 100 100 67 95 85 87 89 100 65 67 69 71 100 98 98 98 65 67 69 71 0.10

Isaac Newton 100 90 100 90 100 90 100 90 100 100 100 100 100 100 100 100 100 100 100 100 98 98 98 90 90 98 88 0.00

Cole Jones 100 100 100 87 73 75 77 79 81 87 89 91 73 75 77 79 81 100 100 100 98 100 65 67 69 71 63 0.05

Angela Allen 100 100 100 87 89 91 93 95 100 100 100 100 100 100 100 95 97 100 98 98 98 90 73 75 77 79 81 0.02

David Cooper 56 58 60 62 64 100 100 100 87 73 75 77 100 100 77 79 81 100 100 100 98 70 72 74 76 78 88 0.00

Nancy Bailey 100 87 89 91 93 95 100 100 100 100 100 100 91 93 95 97 100 98 100 100 98 98 98 90 90 98 88 0.00

Emily Synder 65 67 69 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 74 76 78 90 90 74 76 98 88 0.00

Lori Austin 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 98 98 90 90 98 88 0.02

Jenny Howard 56 58 60 62 71 62 64 73 100 66 68 70 72 74 76 78 100 100 100 60 62 79 66 68 70 68 70 0.03

Anne Lewis 100 86 58 60 100 71 62 64 73 94 66 68 90 72 74 76 78 67 68 69 70 71 98 88 76 78 68 0.04

Nick Johnson 100 100 89 91 73 75 77 79 81 100 100 100 98 100 100 95 85 87 89 100 98 98 98 80 76 78 98 0.01

Nick Spickler 100 93 95 97 100 98 98 98 90 100 89 91 93 95 97 100 100 89 91 93 95 97 98 98 90 90 98 0.00

Joy Williams 75 77 58 60 62 79 66 68 70 72 81 100 100 71 62 64 73 94 66 98 90 90 98 68 90 88 77 0.00

Barbara Hood 100 67 95 85 87 89 91 93 95 97 85 87 100 100 100 71 62 64 73 94 66 68 98 98 90 90 88 0.00

Joe Hoarn 62 63 64 65 66 67 68 69 70 71 100 81 100 100 71 62 64 73 100 100 98 98 64 73 94 66 68 0.08

Payton Bardzell 100 100 100 97 87 67 95 85 87 89 91 93 95 97 100 100 100 95 85 87 89 100 98 90 90 78 98 0.00

Kim Ludwig 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 100 100 79 66 68 70 72 98 98 90 90 98 0.09

Susan Honks 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 90 90 88 100 100 100 100 0.00

The out put must be

First Name Last Name Final Grade

Nick Johnson A

Anne Lewis B

finish the program please

Solutions

Expert Solution

Please find below modified JAVA program. I have added the function to return the grade as per the total grade & average in projects.

#include < iostream > 
#include < fstream > 
#include < string > 
using namespace std;
const int QUIZSIZE = 10;
const int LABSIZE = 10;
const int PROJSIZE = 3;
const int EXAMSIZE = 3;
float
getAverage(float arr[], int size) {
  float total = 0;
  for (int i = 0; i < size; i++) {
    total += arr[i];
  }
  return total / size;
}
char
getGrade(float quiz, float lab) {
  char grade;
  if (quiz > 90 && lab > 90) grade = 'A';
  else if (quiz >= 80 && quiz < 90 && lab >= 80) grade = 'B';
  else if (quiz >= 70 && quiz < 80 && lab >= 70) grade = 'C';
  else if (quiz >= 60 && quiz < 70 && lab >= 60) grade = 'D';
  else grade = 'F';
  return grade;
}
int
main() {
  ifstream dataIn;
  string headingLine;
  string firstName,
  lastName;
  float quiz[QUIZSIZE];
  float lab[LABSIZE];
  float project[PROJSIZE];
  float midExam[EXAMSIZE];
  float finalExam;
  float attendance;
  dataIn.open("grade120.dat");
  if (dataIn.fail()) {
    cout << "File open error!" << endl;
    return 0;
  }
  for (int i = 1; i <= 2; i++) {
    getline(dataIn, headingLine);
    cout << headingLine << endl;
  }
  while (!dataIn.eof()) {
    dataIn >> firstName;
    dataIn >> lastName;
    for (int i = 0; i < QUIZSIZE; i++) {
      dataIn >> quiz[i];
    }
    for (int i = 0; i < LABSIZE; i++) {
      dataIn >> lab[i];
    }
    for (int i = 0; i < PROJSIZE; i++) {
      dataIn >> project[i];
    }
    for (int i = 0; i < EXAMSIZE; i++) {
      dataIn >> midExam[i];
    }
    dataIn >> finalExam;
    dataIn >> attendance;
    float avgQuiz = getAverage(quiz, QUIZSIZE);
    float avgLab = getAverage(lab, LABSIZE);
    cout << "Average quiz is " << avgQuiz << endl;
    cout << "Average lab is " << avgLab << endl;
// call another function to calculate the final greade letter
    char grade = getGrade(avgQuiz, avgLab);      
//write the name + letter to a file
    cout << firstName << " " << lastName << " " << grade << endl;
  }
  dataIn.close();
  return 0;
}

Hope it helps. Thanks!


Related Solutions

#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
#include <iostream> #include <fstream> #include <vector> using namespace std; struct Point{ int x, y; bool operator==(const...
#include <iostream> #include <fstream> #include <vector> using namespace std; struct Point{ int x, y; bool operator==(const Point& p2) { return this->x == p2.x and this->y == p2.y; } bool operator!=(const Point& p2) { return this->x != p2.x or this->y != p2.y; } friend ostream &operator<<( ostream &out, const Point &P ) { out << "(" << P.x << ", " << P.y << ")"; return out; } friend istream &operator>>( istream &in, Point &P ) { char d1, d2, d3;...
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int&...
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int& numberUsed) { cout << "Enter up to " << size << " nonnegative whole numbers.\n" << "Mark the end of the list with a negative number.\n"; int next, index = 0; cin >> next; while ((next >= 0) && (index < size)) { a[index] = next; index++; cin >> next; } numberUsed = index; } int search(const int a[], int numberUsed, int target) {...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
Array based application #include <iostream> #include <string> #include <fstream> using namespace std; // Function prototypes void...
Array based application #include <iostream> #include <string> #include <fstream> using namespace std; // Function prototypes void selectionSort(string [], int); void displayArray(string [], int); void readNames(string[], int); int main() {    const int NUM_NAMES = 20;    string names[NUM_NAMES];    // Read the names from the file.    readNames(names, NUM_NAMES);    // Display the unsorted array.    cout << "Here are the unsorted names:\n";    cout << "--------------------------\n";    displayArray(names, NUM_NAMES);    // Sort the array.    selectionSort(names, NUM_NAMES);    //...
9. #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt");...
9. #include <fstream> #include <iostream> using namespace std; int main() { float bmi; ifstream inFile; inFile.open("bmi.txt"); while (!inFile.eof()) { inFile >> bmi; if( bmi < 18.5) { cout << bmi << " is underweight " ; } else if( bmi >= 18.5 && bmi <= 24.9) { cout << bmi << " is in normal range " ; } else if( bmi >= 25.0 && bmi <= 29.9) { cout << bmi << " is overweight " ; } else...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput);...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput); // Declaring base int N = 30; if (userInput.length() > 10) { cout << 0 << endl; } else { int finalTotal = 0; //Iterates through userInput for(int i = 0; i < 10; i++){ char convertedInput = userInput[i]; // ASCII decimal value of each character int asciiDec = int(convertedInput); //Casts char value from input to int value stringstream chr; chr << convertedInput; int...
#include <iostream> #include <string> #include <array> #include <vector> using namespace std; void f(int x, int &y);...
#include <iostream> #include <string> #include <array> #include <vector> using namespace std; void f(int x, int &y); int main(){ char s1[] = "zoey"; char s2[] = "zoey"; string s3 = s1; string s4 = s2; cout << "1. sizeof(s1) = " << sizeof(s1) << endl; if(s1 == s2) cout << "2. s1 == s2 is true" << endl; else cout << "2. s1 == s2 is false" << endl; if(s3 == s4) cout << "3. s3 == s4 is true" <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT