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
Who sings you aint nothing but a broke boi
Ad libitum [116K]

Answer:

Kanye West

The song is Gold Digger

6 0
3 years ago
Give the names of two different places you might find a number represented in hexadecimal
Paladinen [302]

Answer:

Monday or Tuesday or Wednesday I am going back to work

Explanation:

8 0
2 years ago
Overview In this project you need to design and implement an Emergency Room Patients Healthcare Management System (ERPHMS) that
notka56 [123]

Answer:

Overview In this project you need to design and implement an Emergency Room Patients Healthcare Management System (ERPHMS) that uses stacks, queues, linked lists, and binary search tree ( in addition you can use all what you need from what you have learned in this course ) The system should be able to keep the patient’s records, visits, turns, diagnostics, treatments, observations, Physicians records, etc. It should allow you to

Explanation:

3 0
2 years ago
You are opening a store, and having a working website is an important part of your project plan. The company that started creati
Murljashka [212]
A should be the answer... not having the website will cause you to have to everything by call and things like that ... plz brainliest.
6 0
3 years ago
What is mass storage? A. Storage that this is on-site B. Storage that this is off-site C. Storage that this is on-site AND off-s
KonstantinChe [14]

Answer:

The answer is "Option D".

Explanation:

Data storage requires different methods and tools to the dealing with the massive data volumes. It is distinct from only the storage, that relates to short term areas of data storage.

  • This system memory, even though the computer is switched off, external storage systems retain information.
  • In the sites storage, it uses the cookies to store sites data, that's why except option D all were wrong.

8 0
3 years ago
Other questions:
  • Jennifer frequently uses a few programs on her laptop. Where will she find all the frequently used program icons in her computer
    13·1 answer
  • Explain three applications of data mining
    14·1 answer
  • Use the drop-down menus to describe how Adnan can add shapes to his presentation.
    11·1 answer
  • Which K-Drama was made in 2009?
    5·2 answers
  • Which of the following refers to a collection of colors, fonts, and effects that can be
    6·1 answer
  • You can click the ____ button to undo an automatic correction.
    9·1 answer
  • Un comerciante de régimen código para comprar mercancías gravadas a un comerciante de régimen simplificado precio de venta al pú
    5·1 answer
  • A customer wants to increase his storage capacity by 25gb
    7·1 answer
  • In this activity, you will submit the work you completed for the "Explore: Products" assignment. Type your response directly int
    12·1 answer
  • What causes the hidden node problem in a wireless local area network (wlan)?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!