1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
belka [17]
3 years ago
11

Implement the function fileSum. fileSum is passed in a name of a file. This function should open the file, sum all of the intege

rs within this file, close the file, and then return the sum. If the file does not exist, this function should output an error message and then call the exit function to exit the program with an error value of 1. The exit function is provided by the cstdlib library. Here is how you call the exit function if you want the exit function to return a 1 (has the same result as the main function returning a 1).

Computers and Technology
1 answer:
maria [59]3 years ago
5 0

Answer:

/*C++ program that prompts user to enter the name of input file(input.txt in this example) and print the sum of the values in the file to console. If file dosnot exist, then close the program */

//header files

#include <fstream>

#include<string>

#include <iostream>

#include <cstdlib> //needed for exit function

using namespace std;

//function prototype

int fileSum(string filename);

int main()

{

string filename;

cout << "Enter the name of the input file: ";

cin >> filename;

cout << "Sum: " << fileSum(filename) << endl;

system("pause");

return 0;

}

/*The function fileSum that takes the string filename and

count the sum of the values and returns the sum of the values*/

int fileSum(string filename)

{

//Create a ifstream object

ifstream fin;

//Open a file

fin.open(filename);

//Initialize sum to zero

int sum=0;

//Check if file exist

if(!fin)

{

cout<<"File does not exist ."<<endl;

system("pause");

exit(1);

}

else

{

int value;

//read file until end of file exist

while(fin>>value)

{

sum+=value;

}

}

return sum;

}//end of the fileSum

Explanation:

This is a C++ program that prompts user to enter the name of input file(input.txt in this example) and print the sum of the values in the file to console. If file dosnot exist, then close the program.

Check attachment for sample output screenshot.

You might be interested in
???????????????????????​
lianna [129]

Answer:

nobody is going to do this for 5 points...

3 0
3 years ago
Which of these components is a part of the central processing unit (CPU) of a computer? A. memory B. storage C. control unit D.
erma4kov [3.2K]
The answer is C. control unit
8 0
3 years ago
Read 2 more answers
Paying attention to the trends that might impact your future career is called
charle [14.2K]
It is the research of possible factor, hypothetical situations, sales, trends that might affect your future career (or even your company's future).
4 0
4 years ago
Read 2 more answers
Which of the following occurs during data cleansing?
Diano4ka-milaya [45]

Answer:c)Clean redundant customer data

Explanation:Data cleansing/cleaning is the activity for the elimination of the data which is not required for further use, corrupt, unnecessary etc by detecting it. The data that is being cleared is categorized by levels like irrelevant  data, incorrect data, inaccurate data, redundant data etc.

The data is eliminated by the method of correcting , modifying, reducing unnecessary parts,deleting, etc.Thus, the correct option is option(C).

5 0
4 years ago
In which of the following careers must one learn and use programming languages?
EleoNora [17]

Answer: any job that has programming in it

8 0
3 years ago
Other questions:
  • Why might location be important when searching for a job?
    10·2 answers
  • ANSWER THESE RIDDLES FOR BRAINLIEST ANSWER!!!!
    11·2 answers
  • Which of the following is an example of a consumer
    14·2 answers
  • Robert's employer has agreed to pay half the tuition for Robert to complete his college degree. This benefit is known as what?
    7·2 answers
  • Wireshark or any other monitoring software running on a single computer connected to a switch doesn't see all the traffic on a n
    10·1 answer
  • Most presentations use text: A. To draw attention to content
    8·1 answer
  • (25 POINTS) Some applications work on all devices while others work on some devices. True or False?
    13·1 answer
  • Select the correct answer from each drop-down menu.
    6·1 answer
  • Why were Redditors interested in "Mister Splashy Pants"?
    6·2 answers
  • Games set in modern times are less difficult to a tie to a specific culture than games set in past eras
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!