# lab2 - ENG101 Lab Exercise 2 September 9th and 10th 2008...

This preview shows pages 1–2. Sign up to view the full content.

ENG101 Lab Exercise 2 September 9 th and 10 th , 2008 Quadratic Formula and Rounding Concepts: Writing a simple C++ code from scratch Integer versus floating point math Input/output streaming operators Making an Algorithm out of an equation Quadratic Formula 1. First, change to your eng101 directory, then to your work directory, and create a directory called quadform pierb50XpXX% cd pierb50XpXX% cd eng101 pierb50XpXX% cd work pierb50XpXX% mkdir quadform Change into the new directory and start your text editor of choice (emacs, vim, gedit). Finally, create a file called quadform.cpp. 2. Type the following code into the text editor: using namespace std; #include <iostream> #include "math.h" // Calculate the two solutions of an equation Ax 2 +Bx+C=0 int main() { int a,b,c,d; // equation parameters a,b,c and discriminant d float x,y; // the two solutions (roots) to the equation cin>>a>>b>>c; // get user input d=b*b-4*a*c; // calculate the descriminant x=(-b+sqrt(d))/(2*a); // first root y=(-b-sqrt(d))/(2*a);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/16/2010 for the course ENGR 101 Sectio taught by Professor Ringenberg during the Fall '08 term at University of Michigan.

### Page1 / 2

lab2 - ENG101 Lab Exercise 2 September 9th and 10th 2008...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online