Contents

Instructions

The purpose of this lab is to give you practice with the basics of programming in C++. You should complete both parts in C++.

(Back to top)

Part 1: Skill-by-skill

Implement each of the following inside of a file named lab13-part1.cpp. Make sure it compiles and does each step.

  1. a while loop that prints out every number from 1 to 100
  2. a do while that prints out every number from 1 to 100
  3. a for loop that prints out every number from 1 to 100
  4. open a file called output.txt and use a loop to write every number from 300 to 400, then close the file
  5. open that file back up for reading and read in every number; use an if statement with the mod operator to output the even ones to the terminal screen, then close the file when you're done
  6. create a function called writeFile and move the code from Step 4 to that function; this function should not return anything or take any parameters; make sure to invoke it in main in the spot where #4 use to be
  7. similarly, create a function for #5 called readFile and move the code for #5 to that function; invoke the function where #5 was located in main
  8. create an array to hold 51 numbers; use a for loop to add all of the even numbers between 900 and 1000 (inclusive) to the array
  9. prompt the user to give the number of strings they would like the program to read in; create a dynamic array that holds that number of strings; use a for loop to prompt the user that many time, each time asking for a string and saving it to the array
  10. create a char and set it to a character of your choice; now create a pointer to that char; change the value of the char using the pointer. Then, print out: the value of the char (using the original variable), the address of that char, the address of the pointer, the address stored in the pointer, and the value the pointer points to
(Back to top)

Part 2: Bringing it together

Complete the following in a file named lab13-part2.cpp.

For every number between 1 and 500, print a "|" when a number is divisible by 4, "-" when the number is divisible by 6, and "+" when it is divisible by both. All other numbers should not result in any output. This should all be on one line.

(Back to top)

Submission

Submit your .cpp files to here. You can view the rubric here.

(Back to top)