MFC Programmer's SourceBook : Thinking in C++
Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Exercises

  1. Modify Hello.cpp so that it prints out your name and age (or shoe size, or your dog’s age, if that makes you feel better). Compile and run the program.
  2. Starting with Stream2.cpp and Numconv.cpp, create a program that asks for the radius of a circle and prints the area of that circle. You can just use the ‘ *’ operator to square the radius.
  3. Create a program that opens a file and counts the whitespace-separated words in that file.
  4. Create a program that counts the occurrence of a particular word in a file (use the string class’ operator ‘ ==’ to find the word).
  5. Modify FillString.cpp so that it adds line numbers to each of the input lines as they are added to s.
  6. Change Fillvector.cpp so it prints the lines (backwards) from last to first.
  7. Change Fillvector.cpp so it concatenates all the elements in the vector into a single string before printing it out, but don’t try to add line numbering.
  8. Display a file a line at a time, waiting for the user to press the “Enter” key after each line.
  9. Create a vector<float> and put 25 floating-point numbers into it using a for loop. Display the vector.
  10. Create three vector<float> objects and fill the first two as in the previous exercise. Write a for loop that adds each corresponding element in the first two vectors and puts the result in the corresponding element of the third vector. Display all three vectors.
  11. Create a vector<float> and put 25 numbers into it as in the previous exercises. Now square each number and put the result back into the same location in the vector. Display the vector before and after the multiplication.
Contents | Prev | Next


Go to CodeGuru.com
Contact: webmaster@codeguru.com
© Copyright 1997-1999 CodeGuru