Unformatted text preview:

Lab2: Problem Solving Using C++ in JGraspObjective - The objective of this lab is to solve a small engineering problem using C++. We will focus on these issues:Description- For this lab, you will calculate the area of a shaded geometric shapePreparation- UNDERSTAND LAB 1 please.JGrasp C++ EnvironmentArea CalculationSubmissionEAS230: Programming & Numerical Methods for Engineers Lab 2 Spring 2012Lab2: Problem Solving Using C++ in JGraspObjective - The objective of this lab is to solve a small engineering problem using C++. We will focus on these issues:- Understand the requirements of a problem and the solution algorithm - Implement the solution using C++ in JGrasp- Define real number (non-integer) variables.- Take user input- Output results to the screen- Debug and remove errors- Test and verify the correctness of the resultsDescription- For this lab, you will calculate the area of a shaded geometric shapePreparation- UNDERSTAND LAB 1 please.Enter AND UNDERSTAND this code. Use the filename Area2.cpp. This part will not be submitted. This short program should give you an example of the steps you will need in the area calculation. When you understand every line of this code, move on to the Area calculation.#include <iostream>using namespace std; int main( ) {double x = 0.0;int y = 0;char dummy = ‘ ’; // initialize to a single blank spacecout << "Enter a real number: ";cin >> x;cout << x << endl;cout << "Enter an integer: ";cin >> y;// check if y is negativeif (y < 0){return 0; // if so, quit the program}cout << y << endl;cout << "Enter any character to quit: ";cin >> dummy;} // end of program… on to page 2 …..Assigned: Sunday 1/29 Due: Friday 2/10 by 11:59pm Page 1 of 2EAS230: Programming & Numerical Methods for Engineers Lab 2 Spring 2012JGrasp C++ EnvironmentCreate a new C++ file called Area2.cpp. Area CalculationYour program must calculate the area of the shaded region (the square minus circle) given the radius. The radius will be input from the keyboard and validated (i.e., ensure that the radius is >= 0), and the area will be calculated with decimal point (real number) accuracy and output. Below is the example graph:Error: Reference source not foundSteps1. Define a “double” variable for Radius. A double is a real number, as opposed to an integer. Initialize it to 0.2. Define another double variable to hold the Circle’s Area. Initialize it to 0.3. Define another double variable to hold the Square’s Area. Initialize it to 0.4. Define another double variable to hold the resultant calculation of the shaded area. Initialize it to 0.5. Define another double variable for PI and assign it the value 3.14159.6. Ask the user for the Radius. 7. Check the validity of the radius ( > 0)8. Calculate the Circle’s area using the Radius and Pi.9. Calculate the Square’s area using 2*Radius as the length of one side.10. Compute and print out the area of the shaded region11. Exit (return 0)Adding CommentsAdd comments in the code (using //… or /* … */ ) to explain each step. The comments are for to aid in grading your assignment, to make sure that you understand each step, so please be verbose.SubmissionThe source code file (Area2.cpp) will need to be submitted using UB Learns under this course’s assignment section. The instructions can be found here: http://www.cse.buffalo.edu/~mikeb/UBlearns.doc. Please note: emails are not involved in the submission, either to the instructor, the TAs, or within UB Learns. Your file must be “attached” to the assignment as per the instructions.Done.Assigned: Sunday 1/29 Due: Friday 2/10 by 11:59pm Page 2 of


View Full Document

UB EAS 230 - Lab2 - Problem Solving Using C++ in JGras

Download Lab2 - Problem Solving Using C++ in JGras
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab2 - Problem Solving Using C++ in JGras and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab2 - Problem Solving Using C++ in JGras 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?