Starting Out With C++ By Tony Gaddis 7th/8th/9th Edition


Thank you for stopping by my blog on now the 9th version of Starting Out with C++. I appreciate all the support and emails that I have received from all of you. I want to especially thank those that not only used the blog to get help but also contributed possible solutions to help fill in the holes. Remember that this blog is intended to help and you are not doing yourself any favors by simply copying and pasting one of many possible solutions that I found that work on an exercise problem.

I do intend to write more exam/quiz questions to round out the study guide and more of the programming challenges - when I get more time.  I'm a student also so I hope you understand.

I have Java and VisualBasic info that I could post if there is enough interest.  Leave a comment and let me know if it is worth posting or not.  Good luck in your classes!

12/02/2014. After debating whether to post more on the 7th edition, I've decided to start posting the solutions to the exercises from the 8th edition. I didn't buy the myprogramminglab version this time so you might have to adjust your code accordingly. The compiler I use to write the code is the Microsoft VisualStudio C++ compiler in command line mode so that works with the examples in the book.

Please note that this blog is not part of turing's Craft (www.turingscraft.com) and we do not provide the solution manual for the course (codelab) or myprogramminglab.

I really like Tony Gaddis' Starting Out With books so here we go...

Open Help Request

Here is where you can ask your fellow blog visitors for help also. Since we have a lot of visitors you might be able to get at least a pointer on how to tackle a problem. Please post the problem in the comment section and how you attempted to solve it. 

14.2: Friends of Classes 11220

Solution by nowiita

class Window
{
private:
int width;
int height;
public:
Window(int w, int h)
{
width = w;
height = h;
}
friend bool areSameSize (Window, Window);
};
bool areSameSize (Window obj1, Window obj2)
{
bool same = false;
if (obj1.width == obj2.width && obj1.height == obj2.height)
same = true;
return same;

}

Chapter 6 Quiz Starting Out With C++ 006

Which of the following is the function header?

a. calculateBonus()
b. decimal calculateBonus()
c. return calculatedBonus;

Chapter 6 Quiz Starting Out With C++ 005

What function is automatically called when a program starts in C++?

a. the include function
b. the main function
c. the return function
d. the displayMessage function

Chapter 6 Quiz Starting Out With C++ 004

What is a void function?

a. a function that does not have a body
b. a function that does not return a value
c. a function that doesn't have any parameters
d. a function that doesn't have any arguments

Chapter 6 Quiz Starting Out With C++ 003

Which of the following are parts of the function definition?

a. return type
b. name
c. parameter list
d. argument list
e. body

Chapter 6 Quiz Starting Out With C++ 002

It is a good idea to break up problems into smaller problems that are easily solved?

a. true
b. false

Chapter 6 Quiz Starting Out With C++ 001

A program may be broken up into manageable _____

a. sections
b. blocks
c. subroutines
d. functions

CH5: Programming Challenge: #26

26. Using Files--Savings Account Balance Modification
Modify the Savings Account Balance program described in Programming Challenge 16 so that it writes the final report to a file.

Solution:

CH5: Programming Challenge: #17

17. Sales Bar Chart
Write a program that asks the user to enter today s sales for ve stores. The program should then display a bar graph comparing each store s sales. Create each bar in the bar graph by displaying a row of asterisks. Each asterisk should represent $100 of sales.

Here is an example of the program's output.

Enter today's sales for store 1: 1000 [Enter]
Enter today's sales for store 2: 1200 [Enter]
Enter today's sales for store 3: 1800 [Enter]
Enter today's sales for store 4: 800 [Enter]
Enter today's sales for store 5: 1900 [Enter]
SALES BAR CHART
(Each * = $100)

Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************

Solution:

CH5: Programming Challenge: #15

15. Payroll Report
Write a program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. 

Input Validation: Do not accept negative numbers for any of the items entered. Do not accept values for state, federal, or FICA withholdings that are greater than the gross pay. If the sum state tax + federal tax + FICA withholdings for any employee is greater than gross pay, print an error message and ask the user to re-enter the data for that employee.

Solution:

CH5: Programming Challenge: #10

10. Average Rainfall
Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should rst ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.

Input Validation: Do not accept a number less than 1 for the number of years. Do not
accept negative numbers for the monthly rainfall.

Solution:


CH5: Programming Challenge: #2

2. Characters for the ASCII Codes
Write a program that uses a loop to display the characters for the ASCII codes 0 through 127. Display 16 characters on each line.

Solution


Chapter 5 Quiz Starting Out With C++ 043

The _____ statement causes a loop to terminate early. The _____ statement causes a loop to stop its current iteration and begin the next one.

a.. continue, break
b. break, continue

Chapter 5 Quiz Starting Out With C++ 042

Reading and Writing files in C++.  How can you tell if a file was successfully opened in C++?

assume inFile was defined as an ifstream object

a. test ifstream and see if it is true
b. test inFile and check if it is true
c. test open(inFile) == true
d. check if inFile returns an error.

Chapter 5 Quiz Starting Out With C++ 041

Writing and Reading files in C++.  What can be used to read lines of data from a file?

a. the readLine() function
b. a loop
c. cin
d. inFile

Chapter 5 Quiz Starting Out With C++ 040

Reading and Writing files in C++.  Will the following segment of code read the name of a city?

ifstream inFile;
string city;

inFile.open("cities.txt");
cout << "Reading city name from the file.\n";

inFile >> city; // Read the city name from the file

a. true
b. false

Chapter 5 Quiz Starting Out With C++ 039

Writing and Reading files in C++.  The >> operator combined with an ifstream object can be used to read from a file?

a. true
b. false

Chapter 5 Quiz Starting Out With C++ 038

Writing and Reading files in C++.  Given that outFile has been defined with ofstream, which statement will write the data to a file?

a. cout(outFile) << " Hello Student";
b. cout << outFile << "Hello Student";
c. outFile << "Hello Student";
d. outFile -> "Hello Student";