Programming with C++ Lab - Lab 1 (10 points)
Part A: Area
/ Volume
Program Instructions:
GOAL 1:
- A complete C++ Program has been
provided for you as a text file.
- This program prompts the operator
to enter length and width, calculates the area of a rectangle,
and displays the result.
- Access this code file in volume.txt
- Copy and paste it into your compiler.
- Build and execute it.
GOAL 2:
- Change the program to calculate
the volume of a box.
- Declare double data objects for
length, width, height, and volume. (You will no longer need
a data object for area).
SUBMIT:
- Document (MS Word or something similar) that contains:
- Source Code: volume.cpp (Goal 2 only)
- Logic Plan: Flowchart or pseudocode.
- Output: Screenshot of program execution.
Lab 01 -- Part B: Miles
per Hour
DESCRIPTION:
- This program uses console I/O to
calculate average speed.
- INPUT
- Number of miles driven -- data
type?
- Hours elapsed -- data type?
- OUTPUT
- Average speed (MPH) displayed
in a complete sentence.
- PROCESSING
- Formula for calculating MPH:
mph = miles / hours
PROGRAM INTERACTION:
Enter miles driven:
282.6
Enter driving time (hours):
4.5
The vehicle drove 282.6 miles in 4.5
hours.
Average speed is 62.8 miles per hour.
TEST DATA SETS:
Miles Driven
|
Driving Time
|
MPH
|
282.6
|
4.5
|
62.8
|
1741.0
|
32.0
|
|
31.8
|
.6
|
|
LOGIC:
- Prior to coding, develop your logic
plan to do the following:
- Prompt for miles and hours.
- Calculate average speed using
the formula provided.
- Display output as shown in Program
Interaction (above).
CODING:
- Start a NEW C++ program - speed.cpp. See Suggested Program Structure
below.
- Select identifiers and data types
for the data objects.
SUBMIT:
- Document (MS Word or something similar) that contains:
- Source Code: speed.cpp (Goal 2 only)
- Logic Plan: Flowchart or pseudocode.
- Output: Screenshot of program execution.
SUGGESTED PROGRAM STRUCTURE:
//
Project Name: Assignment 1B - Speed |
// Programmer Name:
your name goes here |
//
Date Written: today's date goes here |
//
Description: Calculates the MPH
of a vehicle |
|
#include <iostream>
// Header File for console I/O |
using namespace std; |
|
// Begin main Function
Definition |
int
main( ) |
{ |
//
initialization |
|
// Declare Data Objects |
Declare your data objects here
|
// Display Identification
on screen |
cout << "Assignment 1B" << endl; |
cout <<
"Programmed by your name here" << endl <<
endl; |
|
//
input |
Code input statements here
|
//
processing |
Code calculation statements here
|
//
output |
Display results here
|
//
termination |
|
//
indicate normal EOJ |
cout <<
endl << "Normal job termination" << endl; |
return
0; |
|
} // end of main
function |
Return
to TOP
|