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
pickupchik [31]
3 years ago
10

Exercise #3: Write a c++ program that reads, from a file called numbers.in, up to 10 numbers, counts and adds the positive value

s and then displays the results. Your program should terminate whenever it either reads 10 numbers or a negative number. Assume at least there is one number in the file.​
Computers and Technology
2 answers:
Annette [7]3 years ago
6 0

Answer:

We should read the file number numbers. in and add up to 10 positive numbers or until there is a negative number.

Explanation:

#include <iostream>

#include <fstream>

using namespace std;

int main()

{   int sum=0,count=0; //Variables for storing sum and counts of positive numbers

   string filename("numbers.in"); //Name of the file to read from

   int number; //The numbers in the file

   ifstream input_file(filename);

   if (!input_file.is_open()) {

       cerr << "Could not open the file - '"<< filename << "'" << endl;//If file could not be opened, displaying error message

       return EXIT_FAILURE; //Returning unsuccessful termination

   }

   while (input_file >> number) //Reading all numbers from file

       {

           if(number>0 && count<10) //If number is is a positive number and it is not the 11th or greater element of file

               {

                   sum+=number; //Adding numbers

                   count++; //Increasing the count

               }

           else //Otherwise we will break out of the loop

               {

                   break;

               }

   }

   if(count<10) //If count is less than 10, then displaying an appropriate message on the console

       {

           cout<<"There are " <<count<<" positive numbers"<<endl<<"The sum of the positive numbers is: "<<sum<<endl;

       }

   else //Otherwise there were more than 10 positive number, then displaying an appropriate message on the console

       {

           cout<<"There are at least " <<count<<" positive numbers"<<endl<<"The sum of the positive numbers is: "<<sum<<endl;

       }

   input_file.close(); //Closing file

   return EXIT_SUCCESS; //indicates successful program execution status

}

Gre4nikov [31]3 years ago
3 0

I don't know

Thanks for the points

You might be interested in
Francis has designed a picture book appropriate for third graders. He wants teachers across the world to freely download use, an
mestny [16]

Answer:

The correct answer will be "Project Gutenberg".

Explanation:

  • Project Gutenberg continues to obtain lots of requests for authorization for using printed books, pictures, as well as derivatives from eBooks. Perhaps some applications should not be produced, because authorization would be included in the objects provided (as well as for professional usages).
  • You can copy, hand it over, or m actually-use it underneath the provisions including its license that was included in the ebook.

So that the above is the right answer.

8 0
3 years ago
Hello can you please help with this if you want to thank you!
nikklg [1K]

Answer:

hardware and software is the answer

8 0
3 years ago
Read 2 more answers
What invention changed the nature of communication and commerce in the first half of the nineteenth century?
serg [7]
Answer: The Telegraph 

Hope this helps you out!
6 0
3 years ago
Read 2 more answers
1 pts Question 5 Which of the following calculations would evaluate to 12? (36) + 2/2, 3* ((6+2)/2), 3* 6+2/2, (306+ 2)/2​
julia-pushkina [17]

Answer:

Could you seperate them if they are different answers? I'm lost, sorry!

Explanation:

5 0
3 years ago
Which of the following statements about programmed decisions is FALSE? a. Programmed decisions deal with repetitive situations.
MA_775_DIABLO [31]

Answer:

Option e: The use of programmed decisions should be limited to noncritical situations.

Explanation:

A repetitive decision or routine that can be managed by developed business  procedures or rules are known as programmed decisions. These kind of decisions are most often known for at certain points in a standard process, and are planned relying on recognized and easily identifiable terms. Programmed decisions generally do not demand much consideration or discussion, and can typically be automated to make certain consistency and save time for decision-makers.

So, the use of programmed decisions should not be limited to noncritical situations.

5 0
3 years ago
Other questions:
  • Which one of the following analog VOM ranges would be selected to measure a DC current of 90 milliamps? A. 10mA B. 1.0A C. 10A D
    14·2 answers
  • When you start to type =av, what feature displays a list of functions and defined names?
    11·1 answer
  • Three business partners are forming a company whose name will be of the form "name1, name2 and name3". however, they can't agree
    13·1 answer
  • Write a program that produces this output:
    10·1 answer
  • You find a list of numbers on the kitchen counter, but you aren’t sure what the numbers represent. This is an example of:
    11·2 answers
  • A problem associated with old drivers is:
    8·1 answer
  • What is the purpose of filters in a database?
    11·1 answer
  • Plz help me to learn python and thx
    7·1 answer
  • How do I get the pictures from my old Samsung phone to put on my iPhone? The Samsung is turned off. Is there a way to transfer i
    8·1 answer
  • Data mining requires specialized data analysts to ask ad hoc questions and obtain answers quickly from the system. select one: t
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!