Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Sample Problems – Conditional Testing 1) Write appropriate IF statements for each of the following conditions. Note: the conditions in problem 1 are not intended to be written as complete C++ programs. Simply write these as the condition would appear within a program: If angle is equal to 90 degrees, print the message “The angle is a right angle,” else print the message “The angle is not a right angle.” If the temperature is above 90 degrees, display the message “above the boiling point of water,” else display the message “below the boiling point of water.” If the number is positive add the number to the variable possum, else add the number to the variable negsum. If the slope is less than .5 set the variable flag to zero, else set flag to one. If the difference between the floating point variables num1 and num2 is less than .001, set the variable approx to zero, else calculate approx as the quantity (num1 – num2) / 2.0. If x is greater than y and z is less than 20, read in a value for p. For the remaining problems below, please provide the following: A flowchart representing the necessary steps to write an appropriate C++ program; The C++ source code. Commonly used Flowchart Symbols Begin/End Process/Calculation Input/Output Decision/Condition 2) In the state of New Jersey, state income taxes are assessed at 2 percent of income for incomes less than or equal to $20,000. For incomes greater than $20,000, state taxes are 2.5 percent of the income that exceeds $20,000 plus a fixed amount of $400. Using this information, write a C++ program that calculates the state income tax for a user-entered income value. In writing your program, include the following symbolic constants: const float LIMIT = 20000.00; const float REG_RATE = 0.02; //represents 2% const float HIGH_RATE = 0.025; //represents 2.5% const float FIXED = 400.00; 3) In a pass/fail course, a student passes if the grade is greater than or equal to 70 and fails if the grade is lower. Write a C++ program that accepts a grade and prints the message A passing grade or A failing grade, as appropriate. 4) Write a C++ program to compute and display a person’s weekly salary as determined by the following expressions: If the hours worked are less than or equal to 40, the person receives $8.00 per hour, otherwise the person receives $320.00 (for a 40-hour work week) plus $12.00 (time-and-a-half) for each hour worked over 40 hours. 5) Write a C++ program that displays either the message I feel great today! or I feel down today! depending on the input. If the character u is entered in the variable ch, the first message should be displayed, else the second message should be displayed. 6) Write a program to display the following two prompts: Enter a month (use 1 for January, 2 for February, etc.): Enter a day of the month (the day is to be represented as an integer): Have your program accept and store a number in the variable month in response to the first prompt, and accept and store a number in the variable day in response to the second prompt. If the month entered is not between 1 and 12 inclusive, print a message informing the user that an invalid month has been entered. If the day entered is not between 1 and 31, print a message informing the user that an invalid day has been entered. (Note: for the purposes of this program, you may consider each month as having 31 days.) If the user enters appropriate values, the program will output the month and day entered by the user. 7) (Data Validation): Write a C++ program that will prompt a user to enter a positive integer. The program will display a message indicating whether the value entered is valid (any positive integer beginning with zero) or or invalid (any negative value). 8) (Menu Selection): Write a C++ program that will prompt the user for a character indicating whether the weather outside meets one of the following conditions: “It is raining”, “it is cloudy”, “it is sunny”. If the first condition is true, the program will display a message to take an umbrella and wear a raincoat, if the second condition is true, the program will display a message to take an umbrella, if the third condition is true, the program will display a message to leave the umbrella and raincoat at home. The program will prompt the user to enter one of the following characters: R – to indicate “raining” C – to indicate “cloudy” S – to indicate “sunny” Note: if a character OTHER THAN one of the above is entered, the program is to indicate that an invalid value has been entered, and the user should re-run the program using one of the above valid letters. 9) Rewrite the above program, allowing the user to enter either an uppercase letter or a lowercase letter as input. 10) (Compound condition using &&) Write a C++ program that will prompt the user to enter an integer between 1 and 100 inclusive. The program will output the sum of all numbers between 1 and the value entered, using the following summation formula: sum = n(n +1)/2. Note: if a value other than one between 1 and 100 is entered, the program is to display a message indicating that an invalid value has been entered, and the user should re-run the program using an appropriate value. 11) Write a C++ program that will prompt the user to enter an integer. The program will display a message indicating whether the value is positive or negative. 12) Write a C++ program that will prompt the user to enter an integer. The program will display a message indicating whether the value is even or odd. For example: if the user were to enter the number 17, the program will display the following: The number 17 is odd. If the user were to enter the number 26, the program will display the following: The number 26 is even. 13) Write a C++ program that will prompt the user to enter two integers. The program will then display the two integers in the order of smallest to largest. 14) Write a C++ program that will prompt the user to enter two integers. The program will then display the two integers in the order of largest to smallest. 15) Write a C++ program that will prompt a user to enter three integers. The program is to store these values in three separate variables. The program will output the three integers in descending order (highest to lowest values). For example, if the following three numbers were to be entered: 9 the output would be the following: 9 2 7 7 2 Note: the integers entered may be different values, or they may be the same values. 16) Write a program that takes as input an integer (negative or positive), and outputs the absolute value of that integer. You may only include iostream.h header file (no math.h header file). (Note: Absolute value is always represented as a positive number. For instance, the absolute value of a positive number is that number, the absolute value of a negative number is the positive of that number. e.g. 17) abs(10) = 10 abs(-10) = 10 notated |10| = 10 notated |-10| = 10 Write a program that inputs 3 integers and outputs the smallest. For example, if the following three numbers were to be entered: 7 the output would be the following: 9 2 2