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 don’t 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.

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

Sign up to vote on this title
UsefulNot useful