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
HELP BRAINLST!!<br><br> How is labor already being automated in supermarkets?
11Alexandr11 [23.1K]

Answer:

Self-checkouts as well.

Explanation:

6 0
3 years ago
Ummm, I hate to interrupt your day, but does anyone know where Mitch72 is????? Because he hasn't talked in a week, and he hasn't
Anettt [7]

Answer:

sorry but no

Explanation:

4 0
3 years ago
Which would be the best reason to consider using plain tables instead of shaded tables in a document?
Eva8 [605]
The best reason to consider using plain tables instead of shaded tables in a document if the document will be copied frequently. The shaded table will  be copied exactly as shaded, and time will be wasted unshading (converting shaded table to plain table) them.  
3 0
4 years ago
Read 2 more answers
Write a complete program that asks the user to input the height and radius of a cone (both of type double) and calls two individ
Vika [28.1K]

Answer:

The program in C++ is as follows:

#include <iostream>

#include <math.h>

using namespace std;

double area(double r, double h){

   double A = 3.14 * r * (r + sqrt(h*h + r*r));

   return A;}

double volume(double r, double h){

   double V = (1.0/3) * 3.14 * r*r * h;

   return V;}

int main(){

   double radius, height;

   cout<<"Radius: "; cin>>radius;

   cout<<"Height: "; cin>>height;

   cout<<"Area: "<<area(radius,height)<<endl;

   cout<<"Volume: "<<volume(radius,height);

   return 0;

}

Explanation:

This declares the area function

double area(double r, double h){

Calculate area

   double A = 3.14 * r * (r + sqrt(h*h + r*r));

Return the calculated area

   return A;}

This declares the volume method

double volume(double r, double h){

Calculate volume

   double V = (1.0/3) * 3.14 * r*r * h;

Return the calculated volume

   return V;}

The main begins here

int main(){

Declare radius and height

   double radius, height;

Get input for radius

   cout<<"Radius: "; cin>>radius;

Get input for height

   cout<<"Height: "; cin>>height;

Call the area function and print the returned value for area

   cout<<"Area: "<<area(radius,height)<<endl;

Call the volume function and print the returned value for volume

   cout<<"Volume: "<<volume(radius,height);

   return 0;

}

4 0
3 years ago
Why is Data-Driven Analytics of interest to companies?
vivado [14]

Answer:

It allows companies to make definitive predictions about the future. It gives companies the ability to make informed decisions.

It helps Data Analysts shape an analytics problem from a business problem.

Explanation:

4 0
3 years ago
Other questions:
  • What are the 6 external parts of a computer system
    8·1 answer
  • Write the definition of a function printDottedLine, which has no parameters and doesn't return anything. The function prints to
    10·1 answer
  • Rick works for the government and is investigating a small business that the government suspects has been cheating on its taxes.
    15·1 answer
  • True or False
    11·1 answer
  • what security threats do you face in your everyday computer usage? list the current security you use on your digital devices wha
    9·1 answer
  • An IT suspects that an unauthorized device is connected to a wireless network. This is a result of pastry sharing on a device br
    13·1 answer
  • When a browser is open on your computer, what browser tool is used to move the webpage to the previously viewed page on the brow
    8·1 answer
  • Hello :) new day <br> which one would u pick?<br> 1. chips 2. Gacha life 3. chocolate?<br><br> hehe
    15·2 answers
  • 10. What Microsoft program is frequently used to develop pictorial representations
    10·1 answer
  • Data will zip through a 5G network much faster than through a 4G network because of the 10-fold difference in _____.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!