Tags:
create new tag
view all tags

Lab 0

Moodle Link

Lab based on Chapter 1.

0) The purpose of this exercise is to produce a catalog of typical syntax errors and error messages that will be encountered by a beginner, and to continue acquainting you with the programming environment. This exercise should leave you with a knowledge of what error to look for when given any of a number of common error messages.

Create a new project, and put in the code below. Make sure you can run it.

#include <iostream>
using namespace std;
int main( )
{
    int number_of_bars;
    double one_weight, total_weight;

    cout << "Enter the number of candy bars in a package" << endl;
    cout << "and the weight in ounces of one candy bar." << endl;
    cout << "Then press return." << endl;
    cin >> number_of_bars;
    cin >> one_weight;

    total_weight = one_weight * number_of_bars;

    cout << number_of_bars << " candy bars" << endl;
    cout << one_weight << " ounces each" << endl;
    cout << "Total weight is " << total_weight << "ounces." << endl;

    cout << "Try another brand." << endl;
    cout << "Enter the number of candy bars in a package" << endl;
    cout << "and the weight in ounces of one candy bar." << endl;
    cout << "Then press return." << endl;
    cin >> number_of_bars;
    cin >> one_weight;
    total_weight = one_weight * number_of_bars;

    cout << number_of_bars << " candy bars" << endl;
    cout << one_weight << " ounces each" << endl;
    cout << "Total weight is " << total_weight << " ounces." << endl;

    cout << "Perhaps an apple would be healthier." << endl;

    return 0;
}

Deliberately introduce errors to the program, compile, record the error and the error message, fix the error, compile again (to be sure you have the program corrected), then introduce another error. Keep the catalog of errors and add program errors and messages to it as you continue through this course.

The sequence of suggested errors to introduce is:

a. Put an extra space between the < and the iostream file name.
b. Omit one of the < or > symbols in the include directive.
c. Omit the int from int main() .
d. Omit or misspell the word main .
e. Omit one of the ( ) , then omit both the ( ) .
f. Continue in this fashion, deliberately misspelling identifiers (cout , cin , and so on). Omit one or both of the << in the cout statement; leave off the ending curly brace } .

You do not need to turn the above part in, only what follows.

1) (50 pts) Write a C++ program that reads in two integers and then outputs both their sum and their product. One way to proceed is to start with the sample program from class and then modify that program to produce the program for this project. Be certain to type the first line of your program exactly the same as the first line in class. In particular, be sure that the first line begins at the left-hand end of the line with no space before or after the # symbol. Also, be certain to add the symbols \n to the last output statement in your program. For example, the last output statement might be the following:

cout << "This is the end of the program.\n";

Hand in the code and three different runs (with different inputs) of the program. Copy the run (inputs and outputs from the "Output" window into a document to turn in on moodle.)

2) (50 pts) Write a program that allows the user to enter a number of quarters, dimes, and nickels and then outputs the monetary value of the coins in cents. For example, if the user enters 2 for the number of quarters, 3 for the number of dimes, and 1 for the number of nickels, then the program should output that the coins are worth 85 cents.

Hand in the code and three different runs of the program.

Submit your programs on Moodle by midnight, August 31.

Grading Table

RequirementGrading CommentsPointsGrade
Working Code for #1 25
Three working runs for #1 25
Working Code for #2 25
Three working runs for #2 25
Total 100

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2018-01-22 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback