is a negative number.";
== 0) {
is zero.";
is a positive number.";
=END CODE=
How many runs should you make for the program written in Programming Exercise #1 to verify that it is operating correctly? What data should you
input in each of the program runs? (2 points)
Answer: 3 Runs total. One to test a negative number, positive number, and a zero.
2. Programming Exercise #2 (Chapter 4)
Write a C++ program that prompts the user to input three numbers. The program should then output the numbers in ascending order. (8 points)
Answer:
=START CODE=
#include <iostream>
using namespace std;
int a, b, c;
void sortArray() {
int arr[3] = {a, b, c};
int t;
for (int i=0; i<3; i++) {
for (int r=2; r>=i; r--) {
if (arr[i] > arr[r]) {
t = arr[r];
arr[r] = arr[i];
arr[i] = t;
}
}
}
a = arr[0];
b = arr[1];
c = arr[2];
}
main () {
cout << "Please enter your 1st number: ";
cin >> a;
cout << "Please enter your 2nd number: ";
cin >> b;
cout << "Please enter your 3rd number: ";
cin >> c;
sortArray();
cout << "Your values are now sorted.
return 0;
}
=END CODE=
3. Programming Exercise #15 (Chapter 4)
They are: " << a << ", " << b << ", " << c << endl;
Write a program that calculates and prints the bill for a cellular telephone company. Use the specifications on page 255 for the details. (15 points)
Submit your assignment using the link above (due on Sunday of this unit; 30 points).
Answer:
=START CODE=
#include <iostream>
#include <string>
using namespace std;
main() {
//Declare Strings.
string acctNum;
string servType;
//Declare Integers.
int regMins = 0;
int dayMins = 0;
int eveMins = 0;
int totMins = 0;
//Declare Doubles.
double regPrice = 0;
double pdayPrice = 0;
double pevePrice = 0;
double amountDue;
//Prompt user to enter the Account Number.
cout << "Enter Account Number: ";
cin >> acctNum;
cout << endl;
TryAgain:
//Prompt user to enter the Service Type to calculate total from.
cout << "Enter Service Type ('R' = Regular, 'P' = Premium): ";
cin >> servType;
cout << endl;
//If Service Type is Regular, then do...
if ((servType == "R") || (servType == "r")) {
servType = "Regular";
//Prompt user to enter the total number of minutes.
cout << "Enter Total Day & Evening Minutes Used: ";
cin >> regMins;
//If Service Type is Premium, then do...
=END CODE=