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
If Tamya makes $1000.00 gross monthly income and her total payroll deductions are $294.00, what is her net income?
Maru [420]

Answer:

$751

Explanation:

From the question we have the following information;

Gross income = $1000.00

Deductions =   $294.00

Now we know that;

Net income = Gross income - Deductions

Therefore;

Net income = $1000.00 -  $294.00

Net income = $751

7 0
3 years ago
Heavy use of computers, combined with information overload and 24/7 accessibility via technology, can lead to
STatiana [176]
Things! :D :D :D :D :D
5 0
3 years ago
Which of the following is not a characteristic of a large database?
BartSMP [9]
C is the correct answer
8 0
3 years ago
Universal Containers has a requirement to integrate Salesforce with an external system to control record access. What option sho
Inessa05 [86]

Answer:

C. Use the SOAP API to maintain the related SObject_share records

8 0
3 years ago
Identify the selector in the following CSS code:
SashulF [63]

Answer:

The right answer is: Option A. h3

Explanation:

The purpose of using selectors in CSS is to find the elements in the HTML page to which the formatting will be applied.

Different type of selectors are used in CSS.

In the given code, h3 is the selector.

All the <h3> elements on the page will be of orange color and will have font size 12.

Hence,

The right answer is: Option A. h3

6 0
3 years ago
Other questions:
  • Given four values representing counts of quarters, dimes, nickels and pennies, output the total amount as dollars and cents. Out
    10·1 answer
  • Driving while wearing headphones or earphones
    12·2 answers
  • What is the main purpose of cutting plane line arrows?
    7·1 answer
  • What is the disadvantages of using proprietary software
    10·2 answers
  • Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed
    13·1 answer
  • Designing a video game takes tons of creativity. What inspires your personal creativity and ideas for video games? Explain and g
    15·1 answer
  • State any three points of importance of local level profession​
    11·1 answer
  • Which tool ia used to create the world wide web?
    15·1 answer
  • Which option will be used to attach email messages ​
    6·1 answer
  • If I use the command right(90), which way will Tracy turn?<br> If correct I mark brainlist
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!