CSC 161 Lab #0

"Review this"

Our first lab is a review of CSC 160 stuff.

Please peek at my template files in the Common Area on the k: drive. They are:

  • widget.h - a sample header file defining the Widget class
  • widget.cpp - a sample C++ file implementing the Widget class

   


1. Hello

One, two, three...

  1. Print "hello, world"
  2. Write a function that prints "hello, world" and call it from main()
  3. Now, ask the user how many hello's he wants, and call your hello function that many times

 Review: Using Mingw, cin, cout, functions



2. Buy Widgets

Ask the user how many widgets he wants to buy and how much they cost. Sales tax is 7%. Print out a nice receipt, something like this:

Quantity 7
Price $1.00
Subtotal $7.00
Tax $0.49
Total $1.49

Reviews: arithmetic operators, output formatting (fancy, dollars)

 


3. C-strings

Write a function that takes a C-string and reverse the characters in it. Something like this:

void reverse( char *str);

Snarf a string from the user and call your function to test it.

Did you do the reversal in place, without allocating another string?

Reviews: C-strings, loops, arrays

 


4. Dogs

Create a Dog class. Dog's have:
  • names (member variable) that you can set and get
  • and they bark (member function) which actually just prints out "Fido says woof"... for a dog named Fido, that is.

Now, in main(), create an array of 7 dogs. Read in a file of 7 dog names... you create the file. For each dog name your read in, set its name in the array. Finally, make each dog bark.

Reviews: classes, objects, basic files