Question

In: Computer Science

(17pts)Write, compile, and test a C++ program that uses an if-else structure for problem 3.7 on...

(17pts)Write, compile, and test a C++ program that uses an if-else structure for problem 3.7 on page 108.

 Use the format specified earlier (initial block of comments with TCC logo, name, etc)

Display instructions so that the user understands the purpose of the program and what to enter.

Display the results in increasing (non-decreasing) order.

Run the program for the following 6 test cases.Turn in a printout of the program and printouts of the 6 test cases.(The result should be the same in all 6 cases!)

Case 1stnumberentered 2ndnumberentered 3rdnumberentered

1 10 20 30

2 10 30 20

3 20 10 30

4 20 30 10

5 30 10 20

6 30 20 10

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{
int num1, num2, num3, smallest, middle, biggest;
cout<< "Enter first number:\t";
cin>> num1;
cout<< "Enter second number:\t";
cin>> num2;
cout<< "Enter third number:\t";
cin>> num3;
  
if ((num1 < num2) && (num1 < num3))
{
smallest = num1;
if (num2 > num3)
{
biggest = num2;
middle = num3;
}
}
  
if ((num1 < num2) && (num3 << num1))
{
smallest = num1;
if (num2 < num3)
{
middle = num2;
biggest = num3;
}
}
if ((num1 > num2) && (num3 > num1))
{
middle = num1;
if (num2 < num3)
{
smallest = num2;
biggest = num3;
}
}
  
if ((num1 < num2) && (num3 < num1))
{
middle = num1;
if (num2 > num3)
{
biggest = num2;
smallest = num3;
}
}
if ((num1 > num2) && (num1 > num3))
{
biggest = num1;
if (num3 > num2)
{
middle = num3;
smallest = num2;
}
}
  
if ((num1 > num2) && (num1 > num3))
{
biggest = num1;
if (num2 > num3)
{
middle = num2;
smallest = num3;
}
}

cout<< "Ascending order is : ";
cout << smallest << ", " << middle << ", " << biggest << endl;
  return 0;
}


Related Solutions

JAVA Program 2: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt...
JAVA Program 2: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt the user for three numbers and displays them in ascending order. First, the program will prompt the user for each of the three numbers. Next, find the smallest value of the three. Then decide which of the other two is the next smallest. Then have the program display the three numbers in ascending order. Be sure to do the following: Determine what the input...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Write a C program that contains a structure that uses predefined types and union. • Create...
Write a C program that contains a structure that uses predefined types and union. • Create a struct with name, age, kind (Either child, college student, or adult), and kindOfPerson (Either kid, student, or adult) • kids have a school field. Students have college and gpa. Adults have company and salary. • Create one non-dynamic struct with the content for a college student: "Bob", 20, K-State, 3.5 • Create one struct dynamically for a kid with: "Alison", 10, "Amanda Arnold...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart for each of the following problems: a) Obtain three numbers from the keyboard, compute their product and display the result. b) Obtain two numbers from the keyboard, and determine and display which (if either) is the smaller of the two numbers. c) Obtain a series of positive numbers from the keyboard, and determine and display their average (with 4 decimal points). Assume that the...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Matrix Calculator Goals Write, compile and test a matrix calculator program Review the concept of pointers,...
Matrix Calculator Goals Write, compile and test a matrix calculator program Review the concept of pointers, and multi-dimensional dynamic arrays Create a simple makefile Write a robust input validation. The purpose of this lab is to get familiar with the software environment we will be using this term, and review some C++ concepts to get prepared for future projects and labs. This lab might be very time-consuming since there are a lot of concepts you need to pick up. For...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
write a c program of an structure based on rings(jewelry)
write a c program of an structure based on rings(jewelry)
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT