Assignment_1 drf 1

# Assignment_1 drf 1 - distance = sqrt ( (x_b - x_a)* (x_b -...

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

//Assignment_1.cpp / # include <iostream> # include <fstream> // file I.O # include <cmath> // for calculate. # include <iomanip> # using namespace std; //for result format. void OpenFiles(ifstream& ins, ofstream& outs); v main() // main function { ifstream ins; //prepare files for reading and writing. ofstream outs; //declare stream variables. OpenFiles (ins ,outs); // open the file "points.dat"and"points1.dat". " if (!ins || !outs) // if files not opened O.K. { cout<<"Files did not open successfully."<<endl; //Show error messa\$ return 1; // give program a error result. } float x_a=0; float x_b=0; float y_a=0; float y_b=0; //defin input v. float midpoint_x=0, float midpoint_y=0; float distance=0; //defin local v. do{ ins.get(x_a, x_b, y_a, y_b); // get points from "points.dat". midpoint_x = x_a / 2 + x_b / 2; //calculate midpoint midpoint_y = y_a / 2 + y_b / 2;

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.

Unformatted text preview: distance = sqrt ( (x_b - x_a)* (x_b - x_a) + (y_b - y_a)* (y_b - y_a)); //distance between the points ( outs<< fixed << setw(20), left<<setprecision(2)<<"("<<x_a<<"", "<<\$ "<<"("<<midpoint_x<<", "<<midpoint_y<<") "<<distance; // output ins.get(points); } while (ins); //loop ins. close(); //close files outs.close(); return 0; // program is successful } void OpenFiles(/*inout*/ ifstream& ins /*inout*/ ofstream& outs) { ins. open("points.dat"); // open the file "points.dat". outs.open("points.out"); // put vcariables of dot result in "points1.dat". " } void points (float x_a, float x_b, float y_a, float y_b_) { cout<< fixed << setw(20) <<setprecision(2)<<"("<<x_a<<", "<<y_a<<") " <<"("<<x_b<<", "<<y_b<<") "<<"("<<midpoint_x<<", "<<midpoint_y<<") "<<distance; " }...
View Full Document

## This note was uploaded on 11/17/2009 for the course CS cs105 taught by Professor Fang during the Spring '09 term at University of Regina.

### Page1 / 2

Assignment_1 drf 1 - distance = sqrt ( (x_b - x_a)* (x_b -...

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

View Full Document
Ask a homework question - tutors are online