prog01 -...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: //------------------------------------------------------------------------// Name: George Corser// Program: CSC 375 Program 1 (Prog01.cpp)// Due Date: 02/13/2009// Compiler: Bloodshed Dev-C++ 4.9.9.2// Comments: MSS (maximum subsequence sum) algorithm analysis:// 1-cubic, 2-quadratic, 3-nlogn, 4-linear.// * This program prints the MSS and the time it takes // to find the MSS of an input file of integers or floats.// * The program must be run from the command line as follows:// prog01.exe algno infile.txt// where algno is the algorithm number, 1, 2, 3 or 4 (see above)// and infile.txt contains a list of integers or floats. // * The program assumes that infile.txt contains integers, // unless the letter "f" exists in the third position // of the input file name, argv[2][2]. // * The program overstates the elapsed time for algorithms 3 and 4 // by a factor of 100. It iterates 100 times for those algorithms // because otherwise no there is no noticeable time difference// reported by the computer clock for the given input data. //------------------------------------------------------------------------#include <iostream> // for cout calls#include <fstream> // for ifstream call#include <string> // for c_str() function#include <vector> // for vector processing, e.g. push_back()#include <sys/time.h> // for time and clock functions#define TIME_START ___t = clock()#define TIME (double(clock() - ___t) / CLOCKS_PER_SEC)#define TIMEFACTOR 100 // to obtain a reading from the computer clockusing namespace std; // to avoid typing "std::" throughout codeint maxSubSum1(const vector<int> & a); // 1 - Cubic int maxSubSum2(const vector<int> & a); // 2 - Quadratic int maxSumRec(const vector<int> & a, int left, int right); // 3 - O(n log n) int maxSubSum4(const vector<int> & a); // 4 - Linear float fmaxSubSum1(const vector<float> & a); float fmaxSubSum2(const vector<float> & a); float fmaxSumRec(const vector<float> & a, int left, int right); float fmaxSubSum4(const vector<float> & a); main(int argc, char *argv) { // -------------------- Declare and initialize variables -----------double ___t; // start timeint algno = 0; // Algorithm number from command lineFILE * pFile; // file containing integers or floatsstring inttext; // text of current integer or floatint MSSval = 0; // integer MSS valuevector<int> intVector; // vector of integersint intsprocessed = 0; // number of integers processedint intdata = 0; // integer converted from text float fMSSval = 0;...
View Full Document

Page1 / 6

prog01 -...

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