Project 3 - Long Integer Class

Project 3 - Long Integer Class - Robert J. England II COS...

Info iconThis preview shows pages 1–4. 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

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: Robert J. England II COS 221 Project 3 Long Integer Class Project done for Prof. Larry Latour Monday, November 10, 2006 The following is the actual code used in the program. There are two classes; one is the LongInteger class, which provides the bulk of the code; the other is the Test class, which tests the LongInteger class extensively. The main program does nothing more than create a Test object, and the constructor of that object performs all of the testing. // LongInteger.cpp : // LongInteger class created by Robert J. England // for COS 221 with Larry Latour // at the University of Maine in Orono // Friday, November 10, 2006 // #include "stdafx.h" #include <iostream> #include <math.h> #include <vector> #include <string> using namespace std; class LongInteger { public : // Constructors LongInteger(); // POST: A long integer equivalent to zero is created LongInteger( int source); // POST: A long integer equivalent to source is created LongInteger(string & source); // PRE: source must be a string of numbers only, with a plus // or minus sign at its first position; no characters other // than numerical digits and the one +/- sign are allowed // POST: A long integer object is created from the string LongInteger( const LongInteger & source); // POST: A new long integer equivalent to this long integer // is created // Modifier methods void assignDigit( unsigned int newDigit, unsigned int k); // POST: The kth three-digit group is assigned to newDigit void negate() {positive = !positive;}; // POST: A positive long integer is set negative, and a // negative long integer is set positive // Accessor methods int getDigit( unsigned int k); // POST: The kth three-digit group is returned if it exists; // otherwise 0 is returned bool isPositive() { return positive;}; // POST: true is returned if the long integer is positive; // false is returned otherwise int length(); // POST: Returns number of single digits in long integer // Copy method LongInteger copy(); // POST: Returns a deep copy of the long integer // Input/Output methods void read(istream & in); // POST: A string is read from the stream, any non-numerical // characters are removed, and the result is assigned to the // long integer void write(ostream & out); // POST: The long integer is printed to the output stream // Arithmetic operators LongInteger operator + (LongInteger & other); // POST: The sum of the long integers is returned LongInteger operator- (LongInteger & other); // POST: The difference of the long integers is returned LongInteger operator * (LongInteger & other); // POST: The product of the long integers is returned LongInteger operator / (LongInteger & other); // PRE: other != 0 // POST: The quotient of the long integers is returned; zero // is returned if divisor is zero LongInteger operator % (LongInteger & other); // PRE: other != 0 // POST: The modulus of the long integers is returned; the // same long integer is returned if divisor is zero // Negation operators LongInteger operator...
View Full Document

Page1 / 21

Project 3 - Long Integer Class - Robert J. England II COS...

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