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

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

View Full Document Right Arrow Icon
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);
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online