diff --git a/MidTest2012_sample.pdf b/MidTest2012_sample.pdf new file mode 100644 index 0000000..d1b38b6 Binary files /dev/null and b/MidTest2012_sample.pdf differ diff --git a/MidTest2013.pdf b/MidTest2013.pdf new file mode 100644 index 0000000..58d6f60 Binary files /dev/null and b/MidTest2013.pdf differ diff --git a/assignment4/Summer_Assignment4_2014.pdf b/assignment4/Summer_Assignment4_2014.pdf new file mode 100644 index 0000000..752f01b Binary files /dev/null and b/assignment4/Summer_Assignment4_2014.pdf differ diff --git a/assignment4/sample_code_assignment4_decimal_digits.cpp b/assignment4/sample_code_assignment4_decimal_digits.cpp new file mode 100644 index 0000000..53c6f05 --- /dev/null +++ b/assignment4/sample_code_assignment4_decimal_digits.cpp @@ -0,0 +1,99 @@ +//////////////// 159201 /////////////////////////////////// +//SAMPLE CODE FOR ASSIGNMENT 4 - Big Numbers +//2012 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +/////// PART A + +//copy the template class List here + + +/////// PART B +class BigNumber { +private: +//complete here... +//include here a List of integers, or shorts etc + +public: +//complete here... +//what methods do you need? + BigNumber(); + ~BigNumber(); + void ReadFromString (string decstring ); + void PrintBigNumber (); + void AddBigNumbers(BigNumber B1,BigNumber B2); +}; + +BigNumber::BigNumber(){ +// anything here? +} + +BigNumber::~BigNumber(){ +//you can keep that empty +} + +void BigNumber::ReadFromString (string decstring ) { + //cout<< "testing string passing: "<< decstring << endl; + //read a string, adding a new node per digit of the decimal string + // To translate 'digits' to integers: myinteger=decstring[index]-48 + + for(int i = 0; i < decstring.size(); i++) { + int temp=decstring[i]-48; + cout << "Digit " << i << " is " << temp << endl; //Comment this out for your final version + //You need to use the AddtoFront() + } +} + +void BigNumber::PrintBigNumber () { +//complete here, print the list (i.e., use FirstItem() and NextItem() ) +//remember that the print out may be inverted, depending on the order you enter the 'digits' +} + +void BigNumber::AddBigNumbers(BigNumber B1,BigNumber B2){ +//complete here. +//use FirstItem(), NextItem() and AddNode() +//to add two big numbers, what do you have to do? Be careful about the carry +//Remember to add the last carry, the resulting number can have one more digit than B1 or B2 +} + +/////// PART C + +BigNumber B1,B2,RES; + +main (int argc, char ** argv) { + string numberstring; + int stringseq=0; + ifstream input_file; + if(argc==2) input_file.open(argv[1]); + else { cout<< "cannot read the file " << argv[1] << endl; exit(0);} + while(!input_file.eof()){ + getline(input_file,numberstring); + if(!input_file.eof()){ + cout << "reading a big number from file:" << numberstring << endl;//Comment this out for your final version + if(stringseq==0){ + B1.ReadFromString(numberstring); + stringseq=1; + } + else B2.ReadFromString(numberstring); + } + } + //print + B1.PrintBigNumber();//PROBLEM: Is the printing inverted? How can you solve this problem? Before or after using AddBigNumbers()? + cout << "+" << endl; + B2.PrintBigNumber(); + cout << "=" << endl; + //compute the addition + RES.AddBigNumbers(B1,B2); + //print the result + RES.PrintBigNumber(); +}