CS 010 - Introduction to Computer Science I
Lab 3.
Strings and Graphical Objects

Points(10 overall)

  1. 2 pts: Attendance(at start and end of lab)
  2. 7 pts: Programs
  3. 1 pt:  Commenting and Style

Collaboration policy:
You will be working in pairs during labs.  Pairs will be randomly selected and will be announced by the TA.  Each week you will have a new random partner.  You will discuss the programs with your partner, but you will still be typing in your own code to show to the TA.  You can help each other debug, give plenty of suggestions and hints, **explain** why things work or don't work, etc.


Lab Objectives

To gain experience with

  1. using the ANSI C++ standard string type to define and manipulate character strings
  2. using objects
  3. drawing graphical shapes

Getting Ready

  1. If you have not already done so, create a directory called lab3 from within your CS10 directory.
  2. You will be writing more than one program during this lab, thus you will want separate directories within lab3 for each program.
  3. Follow the directions from Lab 2 if you need help setting up the directories.

Commenting and Style

  1. Be sure to use good variable names.
  2. Use comments throughout your code to explain your code.
  3. Use good spacing and keep it consistent throughout your program.

Program 1: Strings

Write a program that allows the user to enter in a value between 1,000 and 999,999, showing commas in their input.  Then show the number without commas. 

 

Example 1:

Please enter a number between 1,000 and 999,999:  212,416

212416

 

Example 2:

Please enter a number between 1,000 and 999,999:  7,890

7890

 

Hints:

Read the input as a string, use the length of the string (to find out where the comma is) and the substring function to obtain each substring before and after the comma.  You should not need to use any complex structures such as ifs or while loops.

 


Program 2: Graphical Objects

Write a program that draws a picture of a house.  The example below is an idea, it can be more simple than that, or more elaborate. Try and move lines and points, not just set a new point at each corner.

 

 


Bonus Program (1 pt): Time Object

Write a program that tests how fast a user can type.  Get the time.  Ask the user to type, “The quick brown fox jumped over the lazy dog.”.  Read a line of input.  Get the current time again and display how many seconds it took them to type the statement.