CST1620 C++
Programming
Assignments
Click on this link to turn in
your assignments: \\Rc-hutch-ap\VOL1\HOME\allen_b\CST1620Labs
Note: This link only works if you are connected to the Ridgewater campus network and using Microsoft Internet Explorer. (Netscape cannot be used). If you do not have network access, you may turn your homework in on a floppy disk. You must label the diskette with your name, assignment number, and course number. The diskette must be turned in at the start of class. |
Note: Most of the programming
examples in the textbook can be found on the CD-ROM included with the
book. Data types in C++. If you compile your code in debug mode, you can expect your exe file to be about 550KB for these exercises. If you compile your code in release mode, your files will be about 150KB. |
Lab 1 |
Exercises |
Exercise 1.25
Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words "is larger." If the numbers are equal, print the message "These numbers are equal." |
Exercise 1.26
Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. The screen dialogue should appear as shown in the book. |
Exercise 1.32 Write a program that reads in two integers and determines and prints if the first is a multiple of the second. (Hint: use the modulus operator.)
|
Lab 2 |
Exercises |
||||
Exercise 2.16
Write a program to solve the following: Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driver and gallons used for each tankful. Develop a C++ program that uses a while structure to input the miles driving and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.
|
||||
Exercise 2.28
Write a program that reads in the size of the side of a square and then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all sizes between 1 and 20. For example, if your program reads a size of 5, it should print *****
|
||||
Exercise 2.47 Write a program that uses for structures to print the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks(*) should be printed by a single statement of the form cout << '*'; (this causes the asterisks to print side by side). Hint: The last two patterns require that each line begin with an appropriate number of blanks.
|
Lab 3 |
Exercises |
Exercise 3.19
Define a function hypotenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given. Use this function in a program to determine the length of the hypotenuse for each of the triangles below. The function should take two double arguments and return the hypotenuse as a double. Test data: Hint: In a right triangle a2 + b2 = c2 where a and b are the short sides and c is the hypotenuse. |
Exercise 3.27 Implement the following integer functions:
Hint: Celsius = 5/9 * (Fahrenheit - 32)
and Fahrenheit = (9/5 * Celsius) + 32 |
Lab 4 |
Exercises |
|||||||||||||||||||||||||||||||||||||||||||||||||
Exercise 4.17
Write a program that simulates the rolling of two dice. The program should use rand to roll the first die, and should use rand again to roll the second die. The sum of the two values should then be calculated. Note: Since each die can show an Integer value from 1 to 6, the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and and 12 being the least frequent sums. The figure below shows the 36 possible combinations of the two dice. Your program should roll the two dice 36,000 times. Use a single subscripted array to tally the number of times each possible sum appears. Print the results in a tabular format. Are the results you obtained reasonable? (i.e., there are six ways to roll a 7), so approximately one sixth of all the rolls should be 7.
|
Lab 5 |
Exercises |
Exercise 5.12 Modify the program in Figure 5.24 so that the card dealing function deals a five-card poker hand. Then write functions to accomplish each of the following:
|
Extra Credit - Exercise
5.13 Use the functions developed in
Exercise 5.12 to write a program that deals two five-card poker hands,
evaluates each hand and determines which is the better hand. |
Exercise 5.44 Dates are commonly printed in several different formats in business correspondence. Two of the more common formats are
Write a program that reads a date in the first
format and prints that date in the second format. |
Exercise 5.46 Write a program that inputs a numeric check amount and writes the word equivalent of the amount. Your program should be able to handle check amounts as large as $99,999.99. For example the amount 112.42 should be written as
|
Lab 6 |
Exercises |
Exercise 6.7 Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Create appropriate .cpp and .h header files. Use integer variables to represent the private
data of the class - the numerator and the denominator.
Provide a constructor that enables an object of this class to be
initialized when it is declared. The constructor should contain
default values in case no initializers are provided and should store the
fraction in reduced form. For example, the fraction
|
Exercise 6.8 Modify the Time class of Fig. 6.18 to include a tick member function that increments the time stored in a Time object by one second. The Time object should always remain in a consistent state. Write a program that tests the tick member function in a loop that prints the time in standard format during each iteration of the loop to illustrate that the tick member function works correctly. Be sure to test the following cases:
|
Exercise
6.9 Modify the Date class of Fig. 6.24 to perform error checking on the initializer values for data members month, day and year. Also, provide a member function nextDay to increment the day by one. The Date object should always remain in a consistent state. Write a program that tests function nextDay in a loop that prints the date during each iteration to illustrate that nextDay works correctly. Be sure to test the following cases:
|
Exercise 6.10 Combine the modified Time class of Exercise 6.8 and the modified Date class of Exercise 6.9 into one class called DateAndTime. Modify the tick function to call the nextDay function if the time increments into the next day. Modify function printStandard and printUniversal to output the date and time. Write a program to test the new class DateAndTime. Specifically, test incrementing the time into the next day. |
Exercise 6.11 Modify the set functions in the program of Fig. 6.18 to return appropriate error values if an attempt is made to set a data member of an object of class Time to an invalid value. Write a program that tests your new version of class Time. Display error messages when set methods return error values. |
Lab 8 |
Exercises |
Exercise 8.17
(Modified from the book exercise) Modify the program that you created for Exercise 6.7 in the following ways:
Have the user enter two rational numbers. Use your overloaded relational operators to compare the two rational numbers. Print text describing if the first rational number is greater than, or less than, or equal to the second rational number. In your program use your overloaded operators to perform addition, subtraction, multiplication, and division operations. Print the result in a rational format. |
Exercise 8.19 Develop class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent. The term 2X4 has the coefficient of 2 and the exponent of 4. Develop a complete class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities:
You may hard code the original values into your arrays so that you do not spend a lot of time and effort coding the input mechanism. Have an output method so that the results get printed to the screen. |
Lab 12 |
Exercises |
Exercise 12.17 Write a program that uses a for structure to print a table of ASCII values fro the characters in the ASCII character set from 33 to 126. The program should print the decimal value, octal value, hexadecimal value and character value for each character. Use the stream manipulators dec, oct, and hex to print the integer values. |
Lab 13 |
Exercises |
Exercise 13.1 Modify the program that you wrote in exercise 8.17. Use try catch blocks to catch various execution errors. An execution error that come to mind is having a 0 (zero) in the denominator in a rational or having extremely large integer values for the numerator and denominator causing an overflow condition. Catch the errors and provide the user with the appropriate error message. |
Lab 14 In Exercise 14.12 you will be creating a binary data file. This file cannot be opened in Notepad or any other text editor. To see the results of your binary file that you create, you may want to download a hex editor to view the hex digits that comprise your file. Here is a hex editor that is has a 30 day demo period. |
Exercises |
||||||||||||||||||||||||||||||||||||
Exercise 14.1 Modify the program that you wrote in exercise 13.1 (The Rational problem). In the past, all output was directed to the screen. Direct output to a sequential-access file named "rational.txt". Be sure to output your input data as well so that someone later viewing the file can see both the data that was input to the program and the resulting output data. Every time you run the program, the new output should append to the existing file. Time stamp your output with the current date and time. |
||||||||||||||||||||||||||||||||||||
Exercise 14.12 You are the owner of a hardware store and need to keep an inventory that can tell you what different tools you have, how many of each you have on hand, and the cost of each one. Write a program that initializes the random-access file "hardware.dat" to one hundred empty records, lets you input the data concerning each tool, enables you to list all your tools, lets you delete a record for a tool that you no longer have and lets you update any information in the file. The tool identification number should be the record number. Use the following information to start your file:
|
Lab 15 |
Exercises |
Exercise 15.7 (Simple Encryption) Some information on the Internet may be encrypted with a simple algorithm known as "rot13", which rotates each character by 13 positions in the alphabet. Thus, 'a' corresponds to 'n', and 'x' corresponds to 'k'. rot13 is an example of symmetric key encryption. With symmetric key encryption, both the encrypter and decrypter use the same key.
|
Lab 16 See this page for Lab 16. |
Lab MFC |
Exercises |
Exercise
MFC Your instructor will show you how to create a MFC program using the Visual Studio 6 C++ MFC wizard. Also your instructor will give you an example of a simple MFC program in class. Use your instructor's example as a basis to creating your own MFC program. Take your Rational program that you have been working on, and convert it to an MFC program so the user can enter their rationals in text boxes and the results are displayed on a form. |