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
Change the Towers of Hanoi program so that it does the following: a)Counts the number of ring moves and prints that - instead of
aniked [119]

Answer:

Following are the program in the Java Programming Language.

//import scanner class package

import java.util.Scanner;

//define class

public class Tower_of_Hanoi {

//define static integer variable

public static int count = 0;

//define function

public static void Permute_Arrange(int n, char x, char ax, char to) {

//set if statement

if (n == 1) {

//increament in count by 1

++count;

}

//otherwise  

else  

{

Permute_Arrange(n - 1, x, to, ax);

++count;

Permute_Arrange(n - 1, ax, x, to);

}

}

//define main function

public static void main(String[] args)  

{

//set scanner type object

Scanner sc = new Scanner(System.in);

//print message

System.out.println("Enter less than 0 to exit");

//set the while infinite loop

while(true)

{

//print message

System.out.print("Enter the number of Disks: ");

//get input from the user

int num_of_disk = sc.nextInt();

//set the if statement to break the loop

if(num_of_disk<0)

{

//exit from the loop

System.exit(0);

}

//call the function

Permute_Arrange(num_of_disk, 'A', 'B', 'C');

//print message with output

System.out.println("Total number of Disc Moves is: " + count);

count = 0;

}

}

}

<u>Output:</u>

Enter less than 0 to exit

Enter the number of Disks: 4

Total number of Disc Moves is: 15

Enter the number of Disks: 7

Total number of Disc Moves is: 127

Enter the number of Disks: -1

Explanation:

Here, we define a class named "Tower_of_Hanoi"

  • Set the integer data type static variable "count" and initialize the value to 0.
  • Define void data type static function "Permute_Arrange" and pass three characters type arguments "x", "ax", and to and one integer type argument "n", inside it we set if condition to increment in the count variable otherwise call the function.
  • Finally, we define the main function to get input from the user and pass the argument list in function and call the function.
8 0
4 years ago
Just five types of pointing device,list
posledela

Answer:

five types of pointing devices

Explanation:

Ponting devices

Pointing means point something and the pointing devices are the input /peripheral devices those are used to point the pointer on the screen. We do move cursor on the screen to open the files or any icon.

There are many types of pointing devices but these are quite common which are given below

  1. Computer mouse
  2. Finger on touch screen.
  3. Joystick.
  4. Leap Motion.
  5. Light pen (pen)

1.Mouse

Mouse is most common type of input device that is used for pointing the data on the screen. We press it with our hands and keep pointing the things.

There are three types of mouse

  1. optical mouse
  2. wireless mouse
  3. trackball mouse.

2. Finger on touch screen

In this type of movement the fingers are input devices those we use to see the movement of pointer on the screen and this is most common in this century.

3.Joystick.

Joystick is another input device to point the cursor but it is mostly used in games. Children can use it smartly so it is inculcated in games usually.

4. Leap Motion

The Leap Motion (LM) controller is a latest 3D sensing device for hand posture interaction with a computer. It is having the capability sense the location of the fingers of the hands, as well as the palm position.

5.Light Pen

this is another pointing device which is mostly used to highlight and select the data on the screen.

Note: All of these above pointing devices are most common used now a days. These devices are having new  conventions day by day for the ease of user. This era is basically the era of IT ,so the use of computer must be so easy and conventional for the user so, the innovations and improvement in such devices is made side by side.

3 0
3 years ago
Consider the following sequence, defined from n=2 to 15 (inclusive). Pn=n2−1. Produce a list named primes which only contains va
omeli [17]

Answer:

primes = []

for n in range(2,16):

   pn = n*n - 1

   if is_prime(pn):

       primes.append(pn)

5 0
3 years ago
The resistance in a particular kind of circuit is found using this formula: R1(R2)R1+R2.
jenyasd209 [6]

Answer:

resistance = (R1 * R2) / (R1 + R2)

Explanation:

PYTHON doesn't recognize multiplication like this example >> 3(4)

This is why PYTHON uses this symbol (*)

3 0
3 years ago
Assume a disk cache hit rate (dchr) of 95% and 2 millisecond on average to access a page in cache. If the average access time to
MrRa [10]

Answer:

The answer is provided in the form of explanation

Explanation:

A page fault occurs means that the required page is not in main memory. First OS check for

page in the cache memory, if the page is present then retrieved but if not present then check for

page in main memory and if the page is not present here too then it searches for page in hard

drive. To calculate the expected time, the following formula is used:

Cache hit ratio = 95% = 0.95

Cache miss ratio = 5% = 0.05

Cache access time = 2 millisecond

The average access time of hard drive = 30 milliseconds

Expected time = Hit ratio (cache access time +memory access time) + Miss ratio (cache

access time + 2 * memory access time)

= 0.95 (2+30) + 0.05 (2+2*30)

= 0.95 (32) + 0.05(62)

=30.4 + 3.1

= 33.5 millisecond

Expected time = cache hit ratio * cache access time + (1 – hit ratio) * cache miss ratio

= 0.95*2+(1-0.95)*0.05

= 1.9025

4 0
3 years ago
Other questions:
  • Carly wants to be able to look at a document without having to use the horizontal scroll bar located on the bottom of the screen
    7·1 answer
  • A user receives a phone call from a person claiming to be from technical support. This person knows the users name and that the
    12·1 answer
  • Bugs bunny personality traits
    7·1 answer
  • Keion works as a freelancer creating websites and designing logos for clients. He recently had a hard drive failure and lost wor
    12·1 answer
  • Are you concerned that strangers may have access to the personal information you share on social media platforms? Why or why not
    10·1 answer
  • Jason is driving 1,050 miles from Miami, Florida, to New
    15·1 answer
  • What is modularity? Help asap
    9·1 answer
  • Edhesive assignment 4
    14·1 answer
  • What is it called when a additional document is added to an email
    13·2 answers
  • Write a function that accepts a cell array StudentScores consisting of the following:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!