SOLUTION_4 - CS 31 Introduction to Computer Science I UCLA...

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

View Full Document Right Arrow Icon
CS 31: Introduction to Computer Science I: Winter 2010: Project 4 Solution Page 1 // UCLA Winter 2010 // CS 31 Project 4 // John A. Rohr // February 20, 2010 // // // This program solves a system of simultaneous linear equations. // // If the system has a unique solution, the program finds the solution. // If the system does not have a unique solution, the program reports that. // // The program can handle up to ten equations with ten variables. // // All input is read from the file File4.In. // All output is written to cout and the file File4.Out. // If either of the files cannot be opened, the program terminates. #include <iostream> #include <fstream> #include <iomanip> using namespace std; // ************************************************************************** // * * // * GLOBAL CONSTANTS * // * * // ************************************************************************** const char INFILE_NAME[] = "File4.In"; const char OUTFILE_NAME[] = "File4.Out"; const int MAX_EQNS = 10; // Maximum number of equations const int PRECISION = 4; // Precision of double output const int OUTPUT_WIDTH = 10; // Width of double output const int TERMS_PER_LINE = 3; // Number of terms per output line // ************************************************************************** // * * // * GLOBAL VARIABLES * // * * // ************************************************************************** ifstream fin; // Input file ofstream fout; // Output file
Background image of page 1

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

View Full Document Right Arrow Icon
CS 31: Introduction to Computer Science I: Winter 2010: Project 4 Solution Page 2 // ************************************************************************** // * * // * MAIN PROGRAM * // * * // ************************************************************************** int main() { // Function declarations bool initialize(); // Initialize the program bool getInput // Get the input equations (double mat[][MAX_EQNS+1], // Matrix of equations int &numeq); // Number of equations void displayEquations // Display the equations (double mat[][MAX_EQNS+1], // Matrix of equations int numeq); // Number of equations bool solveEquations // Solve the system of equations (double mat[][MAX_EQNS+1], // Matrix of equations int numeq); // Number of equations void displaySolution // Display the solution (double mat[][MAX_EQNS+1], // Matrix of equations int numeq, // Number of equations bool unq); // Unique solution indicator void finish(); // Terminate the program bool process1; // Processing indicator bool process2; // Processing indicator bool unique; // Unique solution indicator int numeqns; // Number of equations double matrix[MAX_EQNS][MAX_EQNS+1];//Matrix of equations
Background image of page 2
CS 31: Introduction to Computer Science I: Winter 2010: Project 4 Solution Page 3 // Initialize process1 = initialize(); // If the files were opened successfully if (process1) { // Set the output format cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(PRECISION); fout.setf(ios::fixed); fout.setf(ios::showpoint); fout.precision(PRECISION); // Do do { // Get the input equations
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 14

SOLUTION_4 - CS 31 Introduction to Computer Science I UCLA...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online