You are on page 1of 2

ME373 Lab 2: Introduction to C++

ME 373 Lab 2: Introduction to C++


Due at 8:00 a.m. on your lab date the week of January 24th. Pre-Lab Complete this portion before working on the lab. If you dont have a CAEDM account, go to the north end of the east hallway on the fourth floor of the Clyde building. There is a computer there where you can sign up for a CAEDM account. You will need your student ID number. C++ Program Format Throughout the semester, use the following format for your C++ programs. 1) Each program begins with a header which includes a description of the program. For example:
//-------------------------------------------------------------// Filename: lab2.cpp // Author: John Smith // Date: 7 September 2005 // Description: // This program reads in a set of data points from a file, // computes a linear regression best-fit line from these // points, and exports the results to an output file. //--------------------------------------------------------------

2) Following the header, the program statements are in the following order:
pre-processor directives (such as #include <iostream>) main program body variable declarations program statements other functions (Include a header which explains the function)

3) Your programs should also employ good style. This includes appropriate indentation, spacing, and comments. Any user prompts should be simple and descriptive. Write Your C++ Program Write a C++ program that calculates the mean of four numbers entered by the user from the terminal. m = (w + x + y + z)/4 Your program should: a) Prompt the user for the four numbers and read them in. b) Calculate the mean. c) Echo the four numbers back to the terminal. d) Print the mean to the terminal. Three different cases should be examined: Case 1: Declare m, w, x, y, and z to be floats.

ME373 Lab 2: Introduction to C++

Case 2: Declare m to be a float and w, x, y, and z to be ints. Case 3: Use the same variable types as in case 2, except replace the 4 with 4.0 in the denominator of the equation for m. You may write one program that does all the cases or separate programs for each. If you do all the cases in one program, you will need to use more variables than just m, w, x, y, and z. Compile Your Program You should write your program in Microsoft Visual Studio or a similar program. This type of program has both a text editor, and an integrated compiler, so that you can edit your program, compile it, and execute it all in one place. It also has some debugging functions that will allow you to find problems with your code. The TA will show you how to set it up for your program. Run Your Program Enter the following integer values for w, x, y, and z: 3, 7, 1, and 4. Note that these four integers sum to an odd number (15). Use these same four numbers for each of the three cases mentioned above. Report Your Findings Write a memo report using the Suggested Format of Lab Memo Reports (available on Blackboard). In the results section, include your results and an explanation of them in terms of integer division, truncated results, and mixed operations. Your source code and sample input/output for each case should be included as attachments.

You might also like