Exercise 1, C++ Intro
This page last updated on: Jan. 14, 2002
Contents:
Due Date
Jan. 28, 2002 by end of day
Description
1-1
Using the cout object, write a program that displays a single character, a string, and an integer.
1-2
Define a constant double variable dPI = 3.14159265359. Using the iomanip facilities of the cout object, display the value of dPI in the following ways: "3.1416", "0003.14159", "3.14159e+000", and "3.1415926".
1-3
Write a program that prompts the user for a base 10 integer and a base, then displays the number in the requested base. Assume the set of bases is "dec", "oct", and "hex". The program will continue to accept input from the user until she signals from the keyboard that she is done.
1-4
Using the pass by reference operator, write a program that includes a function to prompt a user to enter a dollar amount representing the amount of a bank check, and returns the information as a parameter of the function.
1-5
Create a class to hold and print out a date. Include a constructor that initializes the object with a month, day, and year. Store the month, day and year as separate private members. Include a public method that prints the date to cout in the format mm/dd/yyyy.
Create a program to read in several dates. For each date, use new to create a date object on the heap, print the object's date to cout, and delete the object. You do not have to check if the dates are valid.
1-6
Write a program that counts the lines of code in a source code file. Do not count blank lines and C++-style comment lines (where the first non-blank characters are "//"). Read the file from the standard input stream using the cin object (or use fstream). Report the number of lines to the standard output stream using the cout object.
This page constructed by Cliff
Green, Copyright © 1998-2002.