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
One item you will NOT need to provide when opening up a bank account
gladu [14]

Answer:

You don't need a birth certificate

Explanation:

8 0
3 years ago
Read 2 more answers
Frank wants to revise an employee policy. If he wants to inform all of the employees of the change, what type of document will h
nekit [7.7K]

Answer:idk

Explanation:

4 0
3 years ago
True or False?
Karo-lina-s [1.5K]

Answer:

The given statement is False

Explanation:

OSI or Open System Interconnection is a reference model around which the networks are built. OSI gives us all the information regarding movement of data from a software through physical means to another software. Generally it is used as a guidance tool. Seven layers combine to build an OSI model/

TCP/IP (Transmission control protocol/ Internet protocol) model is in a way implementation of the OSI model. It tells about the end-to-end transmission of data being transmitted using OSI model.

<h3>I hope it will help you! </h3>
5 0
3 years ago
the control programs managing computer hardware and software use the ______ function to control and prioritize tasks performed b
Ira Lisetskai [31]

application management


7 0
3 years ago
You are tasked with securing a small network for a client in which the following requirements must be met: If a user on the priv
mario62 [17]

Answer:

C

Explanation:

It is best to Implement a UTM appliance.

A Unified Threat Management (UTM) system is a type of network hardware appliance, virtual appliance or cloud service that protects businesses from security threats in a simplified way by combining and integrating multiple security services and features.

DescriptionUnified threat management is an approach to information security where a single hardware or software installation provides multiple security functions. This contrasts with the traditional method of having point solutions for each security function.

Cheers

8 0
3 years ago
Other questions:
  • What is the magnitude of the largest positive value you can place in a bool? a char? an int? a float?
    14·1 answer
  • Clicking on the Spelling &amp; Grammar button is one way to correct a spelling error in Word. Please select the best answer from
    7·2 answers
  • What are the features of a strong résumé? Check all that apply.
    7·1 answer
  • If we collect data on the number of wins each team in the NFL had during the 2011-12 season, we have _____________ data.
    10·1 answer
  • People, can anyone point me a highlighter for google chorme ?
    11·1 answer
  • Tell me the most scariest website you know and i'll give you brainlest
    5·1 answer
  • Explaio mode of Operation of x-ray​
    15·2 answers
  • Which of the following tabs on the Ribbon contains the command to add a Quick Part to a document? A Design B Insert C View D Hom
    7·1 answer
  • the application you attempted to authenticate to is not authorized to use cas. contact your cas administrator to learn how you m
    10·1 answer
  • as a pc technician, you are on the road most of the day and use a laptop. when you get back to your office at the end of the day
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!