Conversion between C and C++

profilekadirouzradli
Home.pdf

Homework 3 – Conversion between C and C++ (due Friday, July 2, 2021 at 11 am EDT)

DELIVERABLES AND LEARNING GOALS:

Your goal is to convert all the programs that we have written so far in C into C++. The point of this

homework assignment is to get you comfortable in the Visual Studio IDE and run some of the basic

programs that we have written before. Also, include a document which describes what each program is

doing in a file called comments.txt. If you worked with another student to complete this assignment,

attribute them in your homework by writing “I worked with xxx” on the top of your homework. BE SURE

TO WRITE AND COMPILE YOUR OWN CODE. The comments.txt file must include your own words. Do not

copy and paste from anyone else. Upload all your .cpp files and zip them together into one file

homework3.zip. You should be able to find your .cpp files in a directory like

C:\Users\pamel\source\repos\, for example.

You will need to create a separate solution for each homework problem. In Visual Studio, go to File -> New

-> Project

Select “Empty Project” and hit Next

Name the project something, and hit “Create”

Right click on Source Files -> Add -> New Item. Choose C++ file and name it something meaningful

Type code in and press F5 to run your code!

I have uploaded the former homework problems and lab problems to this assignment. Your goal is to take

the code that I wrote and convert them to C++ programs. Scanf is “unsafe” in C++, so all instances of

scanf(“%d”, x) will have to be converted to std::cin >> x. Also, all header files need to be replaced with

#include <iostream> (remove all instances of #include <stdio.h>, etc). Additionally, make the following

modifications:

1. Battleship.cpp should check if there is already a ship that is located at the spot when a random

assignment is made (make sure there are exactly five ships!)

2. Dnd.cpp should have a player roll multiple dice. Return the top dice value when fighting the

monster. To get new random numbers, place srand(time(0)) in the main function.

3. Gradebook.cpp should ask the user how many grades they want to enter before they start the

program. Calloc should be used to create space for the gradebook. Any grades that are not

entered should count as 0. Be sure to store the grades in memory using pointers.

4. Distances.cpp should be modified to compute the difference between the two distances (in real

life, this is the difference between the “as the crow flies” distance and “actual driving distance).

5. Trivia.cpp should allow you to input text as an answer and check if it’s right (MAKE THIS SIMPLE –

BE SURE YOU ASK QUESTIONS THAT YOU KNOW HOW TO SPELL. It will not work otherwise. ALSO

MAKE ALL ANSWERS JUST ONE WORD. This will keep it simple for std::cin.). Like last time, you

should have four questions - you can reuse questions from your last assignment. However, the

questions must return strings instead of numbers. Hints: Instead of int, have everything return

std::string. Insert #include <string> at the top of the file.