2010 Lab-11

Lab elements include:
 • Classes
 • Constructors
 • Access specifiers
 • Setters
 • Getters
 • Hexadecimal numbers

Getting started

Do your work in your Odin 2010/b/ folder.

Note:
Menu items 1 and 2 were derived from Chapter-13 Algorithm Workbench.
You may have to look in the textbook to figure them out.

Date formats

Program name: dates.cpp

Design a class called Date.
The class should store a date in three integers: month, day, and year.

Data members should have private access.

There should be 3 member functions to print the date in the following forms:
   12/25/2014
   December 25, 2014
   25 December 2014

Demonstrate the class in your program.

Input Validation:
    Do not accept values for the day greater than 31 or less than 1.
    Do not accept values for the month greater than 12 or less than 1.

format of output:
Lab-11 Date formats ------------------- Please enter a month, day, and year: 3 2 2019 Three possible date formats are: 03/02/2019 March 2, 2019 2 March 2019
Stack overflow: pad with zeros For homework: 1. No constructor is allowed in the Date class. 2. No cin from inside the Date class. 3. Date class must have 3 "setter" member functions. Must call the 3 setter functions. Do not write one function that sets all the data. 4. Data class must have 3 date-format member functions.

Car going and stopping

Program name: car.cpp

Write a class named Car that has the following member variables:
   yearModel  An integer that holds the car's year model.
   make       A C-string that holds the make of the car.
   speed      An integer that holds the car's current speed.

The class should have a constructor and other member functions.

Constructor
   The constructor should accept the car's year model and make as arguments.
   These values should be assigned to the object's yearModel and make member
   variables. The constructor should assign 0 to the speed member variables.

Accessors
   Appropriate accessor functions to get the values stored in an object's
   yearModel, make, and speed member variables.

acceleration
   An accelerate function should add to the speed member variable
   each time it is called.
   Add a random value from 2 to 6.

slowing
   A brake function should subtract from the speed member variable each
   time it is called.
   Subtract a random value from 2 to 6.

Demonstrate the class in your program.
Create a Car object, and then call the accelerate function multiple times,
until the car gets up over 25. After each call to the accelerate function,
get the current speed of the car and display it.

Then, call the brake function over and over until the car reaches a speed of
zero or less. After each call to the brake function, get the current speed of
the car and display it. If your car starts going backwards,
set the speed to zero.

You're done.

format of output:
lab-11 Car going & stopping --------------------------- The car is on the starting line... accelerate to 5 accelerate to 10 accelerate to 15 accelerate to 20 accelerate to 25 speed is 25 brake to 20 brake to 15 brake to 10 brake to 5 brake to 0 The car has stopped.
Your output will look different each time your run.

Hexadecimal numbers

Program name: hex.cpp

Write a program with a function that uses a for-loop to count to 14.
Inside the for-loop display a period at each iteration.
Pause exactly one-eighth of a second during each loop iteration.

Required:
All numeric literals in your program must be in hexadecimal format.
At least 2 hexadecimal numeric literals must be used in your code.
There are more than that.

do this...
  · Use usleep for your delay in printing.
  · Do not use a hex conversion calculator to find your delay value.
  · Calculate the hex value yourself using hex values.
    Show your work.

Look at the animation below.

format of output:
lab-11 Hexadecimal numbers -------------------------- Counting to 0xE 123456789abcdef for-loop is running now .............. for-loop has finished.
hint: use flush with cout so each dot displays as it is printed.

Retail items

Program name: inventory.cpp

Write a program with a class named RetailItem.

The RetailItem class holds data about an item in a retail store.

The class should have the following member variables:
  • description A string that holds a description of the item.
  • unitsOnHand An int that holds the number of units in inventory.
  • price       A double that holds the item's retail price.

Write a constructor that accepts arguments for each member variable,
appropriate mutator functions that store values in these member variables,
and accessor functions that return the values in these member variables.

Your program will create three RetailItem objects.
Store the data shown in the sample output.

Do not print from inside the class.
Optional:

You may make an array of RetailItem classes.
Your array must have a size of 3 or more.

format of output:
lab-11 Retail item class ------------------------ Retail store inventory Units Description On Hand Price ------------- ------- ----- Item #1 Jacket 12 59.95 Item #2 Designer Jeans 40 34.95 Item #3 Shirt 20 24.95