To gain more experience in
Write a program that reads in ten integer numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero, and the sum of all the numbers, whether positive, negative, or zero. The user enters them just once each and can enter them in any order. Your program should not ask them to enter the positive and negative numbers separately. Make the number of integers to be entered, in this case 10, a constant using the const modifier.
Here is a sample run of the program: (user input in bold)
Enter 10 integers (positive and negative): 1 4 -5 90 -45 -32 23 100 -8 -49 The sum of all positive numbers is 218 The sum of all negative numbers is -139 The sum of all numbers (positive and negative) is 79
You will need to use a while loop along with an if-else structure. Each iteration of the while loop should take care of one user input. Inside this while loop you will either add the user input to the sum of positives or to the sum of negatives. Parts 3 and 4 will be very difficult and/or tedious if you don't follow this hint.
Write a program that allows the user to enter as many positive or negative integers as they want. How will the user let you know when they are done entering numbers? You can't use a sentinal value of -1 since this is a valid entry now. However your program allows the user to signal the end of input, your program should then output the maximum and minimum of the numbers just entered.
You should also error check for valid input with each number. You can use the fail member function of cin for this. Input validation and cin.fail() are described beginning on page 126 of Big C++. If the user types in bad input, your program should allow them to reenter the input, and not use the bad input in the calculations.
If the user enters the following values when prompted:
45 55 -20 39 -2 99 35 -15
You should output the following:
Maximum = 99 Minimum = -20
Read in the first value before entering the loop. Make this first value the intitial value of both the max and min variables.
This first part is the same as Program 3 from the last lab, Lab 4. You can copy that program into the directory for this program. The following is one way to accomplish this. If Program 3 from Lab 4 was in directory ~/CS10/lab4/p3, you could copy that source file over with the command
cp ~/CS10/lab4/p3/main.cpp main.cpp
This would copy over main.cpp from lab4 as long as you typed this command from within the directory your wanted to copy the file to.
(Same as Lab 4) Write a graphics program that asks the user to click on 2 points within the window. Then draw a rectangle with these points being opposite corners of each other. If the user chooses points that have either the same x coordinate or the same y coordinate (this would cause a horizontal or vertical line instead of a rectangle), output an error message and exit the program, otherwise, draw the rectangle.
For example, if the user clicks on points with the coordinates (1,2) and (4,0), then the 4 corners (Points) of the rectangle would be (1,2), (1,0), (4,0), and (4,2).
(New part for Lab 5) Now have the user click with the mouse in the rectangle you just drew. If they click outside the box, give an error message and allow them to re-click until they click in the rectangle.
Once they have clicked in the rectangle, draw a point where they clicked. Then allow them to move the point one unit up, down, right, or left. Keep asking them for a new direction to move until they run into one of the "walls" of the rectangle.
You can leave each previous point on the screen each time they move to show their path. For a more challenging exercise, clear the screen with each move. This will require you to redraw the rectangle each time.