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
andrey2020 [161]
3 years ago
7

Write a program sum.cpp that reads a sequence of integers from cin, and reports their sum. Example If you have a file numbers.tx

t that contains:
Computers and Technology
1 answer:
Katarina [22]3 years ago
8 0

Answer:

The solution code is as follows:

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. int main()
  6. {
  7.    ifstream data;
  8.    float number;
  9.    float sum = 0;
  10.    
  11.    data.open("numbers.txt");
  12.    
  13.    while (data >> number) {
  14.        sum = sum + number;
  15.    }
  16.    cout<<sum;
  17.    return 0;
  18. }

Explanation:

Firstly, we create a ifstream object, <em>data</em> (Line 9). Then we can use the ifstream object to open the "numbers.txt" (Line 13) and use while loop to traverse through the number in the text file line by line (Line 15). White the loop is ongoing the number in each line is read by >> operator in a similar way to cin and then add each read number to sum variable (Line 16).

At last, display the output (Line 18).

You might be interested in
An administrator is writing into a database and received an error detailed in the exhibit. What two steps need to be taken to re
d1i1m1o1n [39]

An administrator is writing into a database and received an error detailed in the exhibit. The two steps to be taken to resolve this are :

Move the Execute SQL statement to be between Connect and Disconnect. Move the Prompt Message to be before the Disconnect statements.

Explanation:

  • Dynamic SQL refers to SQL statements that are generated at run-time.
  • To disconnect from a database, in the Database Navigator or Projects view, click the connection and then click the Disconnect button in the toolbar or click Database -> Disconnect on the main menu
  • You can also right-click the connection and click Disconnect on the context menu
  • The PROMPT command may be used to display messages to the user, perhaps supplying a short summary of what your script is going to accomplish.
  • The SQL EXECUTE command executes an SQL command and binds the result to 4D objects (arrays, variables or fields).
  • A valid connection must be specified in the current process in order to execute this command. The sqlStatement parameter contains the SQL command to execute.

7 0
3 years ago
Which statements describe OneDrive?
Vesna [10]

Answer:

OneDrive is a storage location on your personal computer.

Explanation:

Its gives u extra storage as well as helps u to take backup for all ur files that are important to u

Hope this helps...

Pls mark my ans as brainliest

If u mark my ans as brainliest u will get 3 extra points

6 0
3 years ago
Read 2 more answers
Write a function that takes a string like 'one five two' and returns the corresponding integer (in this case, 152). A function j
Lelu [443]

Answer:

see explaination

Explanation:

def words2number(s):

words = s.split()

numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

result = ""

for word in words:

if word in numbers:

result += str(numbers.index(word))

return result

4 0
3 years ago
Read 2 more answers
A file that is 242 megabytes is being downloaded. if the download is 15.4% complete, how many megabytes have been downloaded? ro
Lunna [17]
37.26 megabytes have been downloaded
5 0
3 years ago
Define a public static method named s2f that takes two String arguments, the name of a file and some text. The method creates th
frez [133]

Answer:

Java solution (because only major programming language that has public static methods)

(import java.io.* before hand)

public static boolean s2f(String fileName, String text){

   try{

       PrintWriter out = new PrintWriter(new File(fileName));

       out.println(text);

       out.close();

       return true;

   }

   catch(Exception e){

       return false;

   }

}

6 0
2 years ago
Other questions:
  • Developers work together with customers and useras to define requirements and specify what the proposed system will do. If once
    9·1 answer
  • Please help me!! 10 Points are waiting!!
    8·1 answer
  • it says i have brainly plus subscripton but whenever i log onto brainly using my laptop, it says i don't have brainly plus and w
    12·1 answer
  • Which of the following accurately describe the
    9·2 answers
  • What is the value of numX when this program is executed? if 3 &lt; 5 and 8 != 3: numX = 3 else: numX = 7
    13·2 answers
  • Most presentation programs allow you to save presentations so they can be viewed online by saving them as ____
    5·2 answers
  • Select the correct answer.
    9·1 answer
  • Atheel tests a program and gets a NameError. How can this be fixed?
    13·2 answers
  • How bridges are built over water
    14·1 answer
  • Given an array of integers a, your task is to calculate the digits that occur the most number of times in the array. Return the
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!