Question

In: Computer Science

In this assignment, you shall create a complete C++ program that will read from a file,...

In this assignment, you shall create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name Next it will need to read three integer values that will represent the 3 exam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student.

Below is an example of what the calculation would be for the program.

score1 * .3 + score2 * .3 + score3 * .4

use input.open ("studentstxt")

//Read data

input score1

input score2

input score3

The program will then determine the letter grade for that student and write the user ID and the letter grade to a file "studentGrade.txt"

The standard grading scale will be used:

A --> 90 – 100
B --> 80 - 89.99
C --> 70 - 79.99
D --> 60 - 69.99
F --> below 60

Also, do not forget that you will need to include the "fstream" library along with the other ones that you normally include.

Inside the main function definition, declare your variables being sure to give them a descriptive name where it is easy for the reader of the code to know what is stored in each. Along with variables for the values you will be reading out of the file you will also need one set up to use with the input file and the output file. These also need to be descriptive so it is obvious as to which file is being used.

In this program the user will not be entering in any data as it will all come to from the file. Likewise, all output will be written to a file so the user will not see anything come to the screen. To keep from the user being confused as if anything happened or not it is always good to give them a ending statement i.e. Something like the following:

Program has completed and the output can be found in 'studentGrade.txt'

Save the contents of the file

Use your IDE to compile the contents of your source code file

If any syntax errors are detected by the g++ compiler, or any warning messages appear, correct the errors, save the contents of your source code file, and recompile the file. Continue this step until all syntax errors in the program are corrected and no warning messages appear

Link the program. (The g++ compiler automatically performs this link step for you after you compile the program if your program contains no syntax errors)

Test your program by running it several times with different student information to check that you have implemented your algorithm correctly. If any logical errors occur (i.e., program does not fulfill the requirements or produces incorrect output), make corrections in your source code file, save the file, compile and link the file, and run the program again. Continue to do this step until the logical errors are corrected.

Design and Implementation Constraints

Follow the coding standards listed in assignment 1

Use no C++ code features in your program that have not been covered yet in the course

StudentInfo.txt

2437 61 92 79

9065 82 63 95

9816 71 92 59

4607 83 91 95

9747 69 99 61

2481 92 86 59

3893 62 70 71

5735 65 91 68

3735 98 77 68

8085 90 63 97

3247 72 96 89

6548 56 52 56

5859 100 99 68

4740 89 80 97

4424 72 72 69

5494 67 87 70

6114 71 87 96

5700 100 64 79

9890 93 92 92

6786 73 79 97

Solutions

Expert Solution

#include <iostream>

#include <fstream>

#include <string>

#include <sstream>

#include <vector>

using namespace std;

bool isFloat(string str)

{

istringstream iss(str);

float f;

iss >> noskipws >> f; // noskipws considers leading whitespace invalid

// Check the entire string is float

return iss.eof() && !iss.fail();

}

int main()

{

vector<string> id;

vector<string> name;

vector<vector<int>> score;

float gpa;

ifstream inFile("studentInfo.txt");

while (inFile)

{

string s;

//Read until no more lines in text file to read

while (getline(inFile, s))

{

istringstream ss(s);

string token;

int counter = 0;

vector<int> s;

//Separate string based on spaces

while (getline(ss, token, ' '))

{

// id

if (counter == 0)

{

id.push_back(token);

counter++;

}

// name

else if (counter == 1)

{

name.push_back(token);

counter++;

}

// GPA

else if (counter >= 2)

{

if (isFloat(token))

{

s.push_back(stof(token));

counter++;

}

}

}

score.push_back(s);

}

}

// print data

for (int i = 0; i < id.size(); i++)

{

cout << "Id : " << id.at(i) << ", name : " << name.at(i)

<< ", Score is : ";

float sum = 0, avg;

for (int j = 0; j < score.at(i).size(); j++)

{

cout << (score.at(i)).at(j) << " ";

sum += (score.at(i)).at(j);

}

avg = sum / 3;

cout << ", Average is " << avg << endl;

}

if (!inFile.eof())

{

cerr << "Fooey!\n";

}

return 0;

}

studentInfo.txt:

11 rCobrie 92 85 79
12 dMalbri 96 88 72
13 dRmaddo 99 88 72
14 sTest1 96 88 79
15 iJully 94 88 76

Output:


Related Solutions

Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of...
Assignment You shall write a program that: Loads chemical-element data by scanning through the file (accessed...
Assignment You shall write a program that: Loads chemical-element data by scanning through the file (accessed via file path or URL) exactly once. Expects one or more command-line arguments that constitute a chemical formula, as described above. Prints one line containing the molar mass of the compound described by the formula, to six digits after the decimal point. Background Data file There is a file on the server that is relevant to this assignment: /srv/datasets/elements This file contains one line...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
Using OOP, write a C++ program that will read in a file of names. The file...
Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike...
I. General Description In this assignment, you will create a Java program to read undergraduate and...
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, and write them in reverse order to an output file. 1. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. For example, assume your package name is FuAssign5 and your main class name is FuAssignment5, and your executable files are in “C:\Users\2734848\eclipse-workspace\CIS 265 Assignments\bin”. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT