Question

In: Computer Science

***USING C++*** (a) Write a program that reads a text file in which each line in...

***USING C++***

(a) Write a program that reads a text file in which each line in the file consists of a first name, a last name, following by 4 grades (double types) like Tim Hanes 78.3 98.0 80.5 72.3 The program must read every line of the text file, find the average of the 4 grades then print the names followed by the averages (one name per line) in a second file as well as on the monitor. Create the text file with at least 5 entries with the format given in part (a). Give the absolute path of the file in your computer. Test your program in part 2(a) on this file.

Solutions

Expert Solution

#include <fstream>
#include <iostream>
#include <sstream>

using namespace std;

int main()
{
ifstream inFile;
char filename[20];

cout<<"Enter The File Name With Extension\n";
cin>>filename;

inFile.open(filename);

/*Here You Have To Create A File And put some data on it.
Then Save the with Any Extension With File Name As Above Shown */

if (!inFile)
{
cerr << "File example.txt not found." << endl;
return -1;
}
  
ofstream outFile("sum.txt");
/*Here You Have Sum Of File Line By Line Sum */
string line;
  
while (getline(inFile, line))
{
if (line.empty())
continue;

istringstream iss(line);
float sum = 0, next = 0;
while (iss >> next)
sum += next;

cout<<sum
outFile << sum << endl;
}

inFile.close();
outFile.close();
  
cout<<"File Created Successfully Go To Sum.txt File And Open\n";
  
return 0;

}


Related Solutions

Write a program that reads a file line by line, and reads each line’s tokens to...
Write a program that reads a file line by line, and reads each line’s tokens to create a Student object that gets inserted into an ArrayList that holds Student objects.  Each line from the file to read will contain two strings for first and last name, and three floats for three test grades.  After reading the file and filling the ArrayList with Student objects, sort the ArrayList and output the contents of the ArrayList so that the students with the highest average...
Write a program in c that reads the content from the file and stores each line...
Write a program in c that reads the content from the file and stores each line in an int array in heap(using dynamic memory allocation). For example, let the file has elements following (we do not know the size of files, it could be above 100,000 and contents of the file and make sure to convert file elements to int): 10067 26789 6789 3467
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
In C++, write a program that reads data from a text file. Include in this program...
In C++, write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global variables are the actual data points, the mean, the standard deviation, and the number of data entered. All other variables must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function... ALL LINES...
C++ Write a program that reads a line of text, changes each uppercase letter to lowercase,...
C++ Write a program that reads a line of text, changes each uppercase letter to lowercase, and places each letter both in a queue and onto a stack. The program should then verify whether the line of text is a palindrome (a set of letters or numbers that is the same whether read forward or backward). Please use a Queue Class and Stack class.
Write a C++ program that reads a string from a text file and determines if the...
Write a C++ program that reads a string from a text file and determines if the string is a palindrome or not using stacks and queue
Write a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
Write a JAVA program that reads a text file. Text file contains three lines. Place each...
Write a JAVA program that reads a text file. Text file contains three lines. Place each line in an array bucket location. Add to the end of the array list. Print the array.
Write a program that reads a line of text input by the user and places each...
Write a program that reads a line of text input by the user and places each word in a TreeSet. Print the elements of the TreeSet to the screen. This will cause the elements to be printed in ascending order. Using Eclipse for this. TreeSetUse.java.
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. In paragraph 1 Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. In pragraph 2 Replace "We" with v"i" This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT