C++ Assignments

FIRST TWO ASSIGNMENTS

Assignment 1a
Edit the "hello.cpp" file we began on our first day of C++ so that it asks the user for his/her name. It should then print, "Hi (the name), it is nice to meet you!"

Assignment 1b --> A new source file called "1b.cpp"
Write a program that prompts the user for two integers. It should then add, subtract, multiply, and divide the two numbers.
You will need to input the numbers using "cin >> "

After asking for the two numbers, it should then print each calculation in the following form:
"The sum of (the first number) and (the second number) is 79.

The line below will print that assuming your two variables are named num1 and num2.
cout << "The sum of " << num1 << " and " << num2 << " is " << sum << endl;


Assignment 2a --> Quadrant Program
Write a program that will print out the number of the quadrant given the coordinates of a point. For example, (3,4) would be quadrant 1, (-2,3) would be quadrant 2 and so on. Your program should be able to recognize points on either axis or at the origin. Use (0,3), (-5,0), (1,3), (-4,2),
(-6,-1), (2,-9) and (0,0) for your test data. Your program should respond, y-axis, x-axis, 1,2,3,4, and origin. Use nested if’s and not compound conditionals. Test as you go.

Write the main program in a for loop, making it longer as you add more data. Eventually it should look like:

for (int i =1; i<=7; i++)
{
your code
}

Assignment 2b -> IF/ELSE-IF Month Chooser
Write a program that will input the number of a month and print out the name of the month. For example, if 10 is inputted, October should be printed. Loop three times and use 1, 10 and 15 for test data.

Assignment 2c - Using Functions
Use the file pointClass.cpp developed in class and finish the function
quadrant(), by revising your assignment 2a. You should be able to cut and paste
most of the code. Put a loop in the main program to test quadrant() using test data from 2a.

Extra Credit 2d - High/Low Guessing Game:
Write a program that generates a random number between 1 and 100. Prompt the user to guess a number and then respond “too high”,”too low” or “Right!” Loop until the user guesses the number. Keep track of the number of guesses. There is a class called RandGen that can be included to get the random number. Follow these steps:
1. at the top of your source code, #include “rando.h”
2. in your project add the source code, rando.cpp to the source folder
3. in your program, declare a object of type RandGen
RandGen rand;
4. assign the random number to a variable
int number = rand.RandInt(1,100);



Assignment 3a -> Using Switch Statements
Rewrite 2b using the switch statement and a while loop as in the example above.

Assignment 3b (Extra Credit) -> The Decoder
There has been a break down in some highly confidential communications within your organization. You have been asked to devise a very simple code for which only the privileged parties will have the decoder. You choose to use letters to represent letters in a random pattern. The following table gives the code

actual encoded actual encoded actual encoded
a g j b s n
b z k u t k
c m l o u t
d r m s v v
e w n d w x
f a o f x q
g c p y y e
h i q h z j
i p r l

Write a decoder. Each message will end with two periods (..). If you define
char chr;
to hold the characters in the code, instruction cin>>chr ignores spaces which makes a message difficult to read. Use cin.get(chr) Decode these messages as your test data. (Please resist the desire to decode by hand). Your program should output the decoded message. It is not necessary to make your decoder case-sensitive unless you wish to.

Xwoo rfdw..
Gd PLN miwmu fd Sln. Ywddpdckfd’n kgq lwktldn ign mfsw ty mowgd..