× Home (CS 111) Lectures Assignments Review Ryba's Website

Details

This set of problems and coding challenges are to be done in lab and at home.
All the cpp files from this assignment should be in a folder.
The name of the folder should follow this format:
lastName_firstName_#2
For example, my name is Alex Chen, folder name will be "Chen_Alex_#2"
Failure to follow this naming convention will result in your assignment not being graded.
The folder is to be zipped and submitted on blackboard on the due date.

#1

Write a checkout.cpp program that does the following:

  1. Ask the user to enter the price of their items. The user can enter as many items as they want until the user enters the integer 0.
  2. Print out the total of their checkout.
  3. If the sum is greater than $100, print out "Thats Expensive!"

#2

Write a reverse.cpp program that does the following:

  1. It asks the user to enter an integer between 100 and 9999.
  2. If the entered number is out of range, the program forces the user to enter more numbers until one in the correct range is given.
  3. Then the program prints the digits in the number (in reverse) on separate lines.
Here is an example of how the program should work:
Enter an integer between 100 and 9999: 8976
6
7
9
8

#3

Write a triangle.cpp program that does the following:

  1. It asks the user to enter a positive integer.
  2. The program reads a value x entered by the user. If the value is not legal, the program repeatedly makes the user type in another value until a legal value of x has been entered.
  3. The program prints a triangular display which has the number x on its top row. Each later row is obtained by omitting the last digit from the number on the previous row.
For example, if the user enters 19683 for x the program should print the following picture.
19683
1968
196
19
1

#4

Write a reverseSum.cpp program that does the following:

  1. It asks the user to enter a positive integer.
  2. If the input is illegal, the program should terminate.
  3. The program prints the digits of the number in reverse order (separated by spaces) and then gives their sum.
For example, if the user enters 19683 the program should print the following output.
3 8 6 9 1 sum to 27

#5

Write a oddCount.cpp program that does the following:

  1. Ask the user to enter an integer between 1000 and 1000000
  2. If the user enters an invaild input ask the user to try again. The user only has 3 tries. If they fail all 3 times, terminate the program
  3. The Program prints out the number of odd numbers in that integer
For example, if the user enters 167256. The program prints: 3 odd numbers

#6

Write a big.cpp program that does the following:

  1. Ask the user to enter a positive integer with at least 2 digits.
  2. If the user enters an invalid input, ask to try again.
  3. Print out the biggest integer in the user's number
For example, if the user enters 167256. The program prints: 7

#7

Write a factor.cpp program that does the following:

  1. Ask the user to enter a 2-digit number, and store it as an int.
  2. If the input is not a 2-digit number, repeatedly ask the same question until the user enters a 2-digit number.
  3. Print all positive factors of the number, in ascending order, one per line. A number i is a factor of n if when you divide n by i, the remainder is 0.
  4. Then print the total number of factors.
Example:
Enter a 2-digit number: 15
Factors:
1
3
5
15
15 has 4 factors.

#8

Write a star.cpp program that does the following:

  1. Ask the user to enter a number divisible by 10
  2. If the user enters an invalid input, terminate the program
  3. Divide the input by 10 and store the answer in a variable x
  4. Print out x number of rows of 10 "*"
For example, if the user enters 50. The program prints:
**********
**********
**********
**********
**********