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]
4 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]4 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 operating system is:
Shalnov [3]

Answer:

System Software

Explanation:

An operating system is a system software that manages computer hardware as well as other things.

3 0
3 years ago
Después de un incidente de seguridad del cliente, el equipo realiza un análisis en profundidad de cada paso dado por los atacant
klio [65]

Explanation:

Respuesta al incidente

5 0
3 years ago
As we move up a energy pyrimad the amount of a energy avaliable to each level of consumers
AleksandrR [38]

Explanation:

As it progresses high around an atmosphere, the amount of power through each tropic stage reduces. Little enough as 10% including its power is passed towards the next layer at every primary producers; the remainder is essentially wasted as heat by physiological activities.

8 0
3 years ago
Suppose B = [1, 2 3; 4, 5,6; 7,8,9], write a program with “for” loops that
Sidana [21]

Answer:

You don't really need the for loop to calculate B square.

The element-wise multiplication operator can help you get the square of each element of B.

B = [1, 2 3; 4, 5,6; 7,8,9];

B = B.^2;

Hope this helps!

5 0
3 years ago
What kind of error is there in this line of code: pritn(“Hello, world!”)?
ivolga24 [154]

Answer:

3.algorithm error

4 0
2 years ago
Read 2 more answers
Other questions:
  • Sarah is working on a project in which she needs to record all the extracurricular activities in her college. Her college teache
    13·2 answers
  • 6. When you don't have enough room to stop, you may _______ to avoid what's in front of you.
    14·1 answer
  • The part you should check first when you are servicing a sparking universal motor is the A. commutator. B. armature. C. brushes.
    9·1 answer
  • Diagnosing is solving the problem, and trouble shooting is figuring out what the problem is.
    15·1 answer
  • What makes us see continuously moving images when still images appear in rapid succession
    11·1 answer
  • Give two reasons you should be aware of your computer's system components and their characteristics.
    10·1 answer
  • All the read/write heads a hard disk are controlled by a(n) ____ which moves the read/write heads across the disk surfaces in un
    13·1 answer
  • You would use the _______ conditional formatting options when analyzing a worksheet in which you want to highlight the highest o
    13·1 answer
  • PLEASE HELP ME !!!!
    15·1 answer
  • If you click on repeat header rows what will happen?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!