讲解CSci 1113、解析C/C++编程、C/C++语言辅导、C/C++程序调试、辅导C/C++设计

- 首页 >> C/C++编程

CSci 1113: Introduction to C/C++

Programming for Scientists and Engineers

Homework 1

Fall 2018

Due Date: Wednesday, September 26, 2018 before 11:00pm.

Instructions: This is an individual homework assignment. There are two problems worth

20 points each. Solve the problem below by yourself (unlike the labs, where you work

collaboratively), and submit the solution as a C++ source code file. Here are a

few more important details:

1. Unlike the computer lab exercises, this is not a collaborative assignment.

2. Because all homework assignments are submitted and tested electronically, the following

are important:

? You follow any naming conventions mentioned in the homework instructions.

? You submit the correct file(s) through Moodle by the due deadline.

? You follow the example input and output formats exactly given in each problem description.

? Regardless of how or where you develop your solutions, your programs compile

and execute on cselabs computers running the Linux operating system.

3. You should test your program on other test cases (that you make up) as well. Making up good test

cases is a valuable programming skill, and is part of ensuring your code solution is correct.

Problem A: Distance conversion (20 points)

Write a C++ program that first asks you to enter a distance with units. Then the program should ask

which distance you want to convert it to. You should display the desired unit conversion.

The units your program should be able to convert from/to are:

inches : “in” or “inches”

feet : “ft” or “feet”

meters : “m” or “meters”

centimeters : “cm” or “centimeters”

Your program should be able to accept the input either as the shortened version right after the number

(see example 1) or as the full name after a space (see example 2). This applies to both the units before

and after the conversion. The final answer should be the converted amount without units.

Use the following conversions:

12 inches = 1 foot

1 foot = 0.3048 meters

1 meter = 100 centimeters

Example 1 (user input is underlined):

Enter distance with units:

200m

What do you want to convert this to?

inches

7874.02

Example 2 (user input is underlined):

Enter distance with units:

1.3 feet

What do you want to convert this to?

cm

39.624

When you are done, name the source code file <username>_1A.cpp. Here you replace

<username> with your U of M email address; for example, if your email address is

smithx1234@umn.edu, your file should be named smithx1234_1A.cpp. Then submit your

program using the HW 1 Problem A submission link in Moodle.

Problem B: Elementary school quiz (20 points)

You are making an electronic quiz for some children in school. You are going to ask the following 5

questions and tell them their percent correct at the end.

Question 1: 5+7=?

Question 2: 5-7=?

Question 3: What animal goes “woof”?

Question 4: What are the three primary colors?

Question 5: What state do we live in?

These questions should have the following answers:

Answer 1: 12

Answer 2: -2

Answer 3: dog

Answer 4: blue green red (in any order)

Answer 5: minnesota

Ask the questions in the exact order shown above. The answer will always be in lower case and exactly

as shown above, except question 4 can have the colors in any order (so answering “red green blue” is

correct, but not “green green green”). You can assume they will always give three colors for question 4.

Example 1 (user input is underlined):

Question 1: What is 5+7?

200

Question 2: What is 5-7?

-2

Question 3: What animal goes "woof"?

doggie

Question 4: What are the three primary colors?

green blue pink

Question 5: What state do we live in?

minnesota

Your percent correct:

40

Example 2 (user input is underlined):

Question 1: What is 5+7?

12

Question 2: What is 5-7?

-2

Question 3: What animal goes "woof"?

dog

Question 4: What are the three primary colors?

red green red

Question 5: What state do we live in?

minnesota

Your percent correct:

80

When you are done, name the source code file <username>_1B.cpp. Here you replace

<username> with your U of M email address; for example, if your email address is

smithx1234@umn.edu, your file should be named smithx1234_1B.cpp. Then submit your

program using the HW 1 Problem B submission link in Moodle.


站长地图