Professional Documents
Culture Documents
SD234 - Unit 3 - Assn B1
SD234 - Unit 3 - Assn B1
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.
b << ", " << c << endl;
return 0;
}
=END CODE=
3. Programming Exercise #15 (Chapter 4)
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).