OOP Lab-04 Common Solution
OOP Lab-04 Common Solution
#ifndef BIG_NUMBER_H
#define BIG_NUMBER_H
#include<iostream>
using namespace std;
enum Comparison
{
EQUAL,SMALL,LARGE
};
class BigNumber
{
char* number;
int numberLength;
int getStartingZeros(const char *);
int getStrLength(const char*);
void copyStr(const char* , char* );
public:
BigNumber(const char *);
BigNumber(const BigNumber &);
~BigNumber();
BigNumber add(BigNumber);
void print();
Comparison compare(BigNumber);
};
#endif // !BIG_NUMBER_H
BigNumber.cpp
#include<iostream>
//Private Functions:
int BigNumber::getStartingZeros(const char* number)
{
int startingZeroes = 0;
while (number[startingZeroes] == '0') //for calculating zeroes at
start
startingZeroes++;
return startingZeroes;
}
Sample Runs:
999 + 999 = 1998 ---- (2)
41634 + “” = 41634 ---- (2)
23 + 23 = 46 ---- (1)
990 + 10 = 1000 ---- (1)
1000 + 1 = 1001 ---- (1)
Logic:
The array on heap must be deleted --- (-1)
Quick Revision:
BigNumber(const char *); ---- (1.5)
for nullptr and empty ---- (0.5)
for making deep copy ---- (1)
Atomicity for length and copyStr ----- (-1)
Logic:
The array on heap must be deleted --- (-1)
Atomicity --- (-1)
Penalty Matrix:
Labs
Penalty List
1 2 3 3 5 6 7 8 9 10 11 12 13 14 15 16
Indentation
putting { Infront of loop header,
0 0 0 0
in do while, putting while with
closing }
- -
Meaningful Variable Names -2
2 2
Atomicity
Syntax error 0 0 0 0
Linker error 0 0 0 0
Continue statement 0 0 0 0
Multi-filing 0 0
- -
Global functions
3 3