SlideShare a Scribd company logo
COP3330 Programming Assignment 3 
The bigint class 
Objective 
1. Practice building class with operator overloading. 
Overview 
The native int type in C++ cannot store large integers of more than 10 decimal digits. In 
this project, you will implement a bigint class that behaves like the int type, but can 
handle unsigned integers of up to 45 digits. 
Details 
1. You are to build a class named bigint that can deal with up to 45 decimal digits of 
unsigned integers. The bigint class is specified as follows. 
2. The bigint class should have a five-element array (int v[5];) as its private date 
member. Each element should store 9 decimal digits. For example to store integer 
1,300,000,000,000,900,000,000,100,000,000. You should have v[0] = 100000000, 
v[1] = 900000000, v[2] =0, v[3]= 1300, and v[4] = 0. 
3. The bigint class should have the following constructors: 
bigint(); // default constructor, set the value to be 0 
bigint(int x0); // set the value to be x0 
bigint(int x0, int x1); // set the value to be x1*109+x0 
bigint(int x0, int x1, int x2); // set the value to be x2*1018+x1*109+x0 
bigint(int x0, int x1, int x2, int x3); 
bigint(int x0, int x1, int x2, int x3, int x4); 
4. To make bigint behave like int, you must overload the following operators 
a. The extraction operator >> for reading a bigint number from an input stream. 
The input number can have up to 45 digits. Following are two legitimate 
bigint numbers that can appear as input: 
1300000000000900000000100000000 
9999999999999999999999999999999999999999999 
b. The insertion operation << for output a bigint number to an output stream. 
The number must be output like a regular int number with the first digit 
being a non zero.
c. 2 arithmetic operators + and – (*, and / are omitted for this type to simplify 
the program). 
d. 6 comparison operators <, >, <=, >=, ==, and !=. 
5. Once the class is implemented, you can test your implementation using the 
proj3_driver.cpp program. You should also write other driver programs to do a 
thorough test of your bigint implementation. Put your bigint class declaration in 
proj3_bigint.h and your bigint class implementation in proj3_bigint.cpp. You should 
be able to compile the program by the command ‘g++ proj3_driver.cpp 
proj3_bigint.cpp’. Redirect proj3_test.txt as the standard input, the output of the 
program should be identical to proj3_test_out.txt. 
Submission 
The due time for this assignment is June 5 (Wendesday), 2013. 11:59pm. 
Tar all of your files for this assignment, which should include at least three files 
proj3_bigint.h, proj3_bigin.cpp, and bug_fixing_log.txt, name the tar file 
yourlastname_firstinitial_proj3.tar and submit the tar file in blackboard. The bug fixing 
log file must follow the template given in project 1. 
Grading policy 
The program must work on linprog. O point for programs with any g++ compiler error on 
linprog. You will need to track compiling errors that you fixed by yourselves in a log for 
fixed compiler bugs that needs to have at least two entries for 5 points/each entry (10 
points max) that are different from those in the bug fixing log in projects 1 and 2. 
· Program with no compiler error (20 points) 
· Log for fixed compiler bugs (10 points) 
· The default constructor and the overloaded << operator (20 points) 
· Other four constructors (3 points each, 12 points total) 
· Six comparison operators (2 points each, 12 points total) 
· + and – operators (8 points each, 16 point total) 
· The >> operator (10 points) 
Hints 
1. Start the project as soon as possible. 
2. You should first create proj3_bigint.h and have an empty implementation in 
proj3_bigint.cpp for each member and friend function with the body of the function 
containing one line
cout << “XXXX function has not been implemented.n” ; 
3. You should then compile the proj3_bigint.cpp and proj3_driver.cpp and run the 
code. From here, you can implement and test one function after another until the 
whole class is implemented. 
4. You should then implement the default construct, and write a simple operator<<() 
function that simply prints out the values of v[0], v[1], v[2], v[3], v[4]. 
5. After that you can implement the functions in the following order: the << operator, 
other constructors, the comparison operators, the arithmetic operators, and the >> 
operator. Remember to compile and run the program at least once everytime you 
add one function. 
6. To implement the << operator, you will need to output potentially 5 integers. You 
must use setw(9) and setfill(‘0’) to output each value besides the most significant 
non-zero integer. You must have ‘#include <iomanip>’ in the file in order to use 
these functions. The following line is an example to use these functions. 
s << setfile(‘0’) << setw(9) << vv.v[j]; 
7. To implement the >> operator, you can first read the string of digits into a character 
array and then manually convert it into a bigint number. 
8. To implement the + and – operators, you must pay special attention to the carry bit 
in the operations. 
9. To see the prototype of the overloaded operators (+, ==, >>, <<), check the examples 
in lecture 6.

More Related Content

PPT
operators and expressions in c++
DOCX
Exp 3-2 d422 (1)
PPS
C programming session 03
PPT
Operators in C++
PPTX
Functions in c++
PPSX
CS106 Lab 9 - 1D array
DOCX
Programming fundamentals
PPTX
Functions in c++,
operators and expressions in c++
Exp 3-2 d422 (1)
C programming session 03
Operators in C++
Functions in c++
CS106 Lab 9 - 1D array
Programming fundamentals
Functions in c++,

What's hot (19)

PPTX
Increment and Decrement operators in C++
PPT
Conversion of Infix To Postfix Expressions
DOCX
Ankita sharma focp
PPT
Type Casting in C++
PPTX
Infix to postfix
PDF
Write declarations for each of the following variables: a. amounts is a...
PPTX
Infix-Postfix expression conversion
PPTX
Prefix, Infix and Post-fix Notations
PPT
Infix to Postfix Conversion Using Stack
PPTX
Evaluation of postfix expression
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PPTX
Operators in C & C++ Language
PDF
Programs that work in c and not in c
DOCX
Quiz 10 cp_sol
PPTX
Infix postfixcoversion
PPT
Tcs nqt 2019 p 1
PPT
Expression evaluation
Increment and Decrement operators in C++
Conversion of Infix To Postfix Expressions
Ankita sharma focp
Type Casting in C++
Infix to postfix
Write declarations for each of the following variables: a. amounts is a...
Infix-Postfix expression conversion
Prefix, Infix and Post-fix Notations
Infix to Postfix Conversion Using Stack
Evaluation of postfix expression
Lecture 2 C++ | Variable Scope, Operators in c++
Operators in C & C++ Language
Programs that work in c and not in c
Quiz 10 cp_sol
Infix postfixcoversion
Tcs nqt 2019 p 1
Expression evaluation
Ad

Viewers also liked (17)

PDF
P4
PDF
Lo39
PDF
E7
PDF
Lo37
PDF
T2
PDF
P2
PDF
T4
PDF
T3
PDF
E10
PDF
Lo27
PDF
Lo17
PDF
Lo48
PDF
E8
PDF
P1
PDF
E9
PDF
T1
PDF
P5
P4
Lo39
E7
Lo37
T2
P2
T4
T3
E10
Lo27
Lo17
Lo48
E8
P1
E9
T1
P5
Ad

Similar to P3 (20)

DOCX
EN3085 Assessed Coursework 1 1. Create a class Complex .docx
PDF
DeVry GSP 115 All Assignments latest
PDF
Ds lab handouts
DOC
Cs2312 OOPS LAB MANUAL
PDF
C++ normal assignments by maharshi_jd.pdf
DOCX
Oops lab manual
DOCX
AU exam
PPT
Chapter 3 Expressions and Inteactivity
DOCX
Oops practical file
PPTX
C++ Homework Help
PDF
CBSE Question Paper Computer Science with C++ 2011
PDF
Object Oriented Programming Using C++ Practical File
DOCX
Practical File of c++.docx lab manual program question
PPT
14 operator overloading
PPTX
Lecture05 operator overloading-and_exception_handling
DOCX
Comp 220 ilab 6 of 7
ODT
(4) cpp automatic arrays_pointers_c-strings_exercises
PDF
Acm aleppo cpc training ninth session
DOC
Oops lab manual2
PDF
c++ lab manual
EN3085 Assessed Coursework 1 1. Create a class Complex .docx
DeVry GSP 115 All Assignments latest
Ds lab handouts
Cs2312 OOPS LAB MANUAL
C++ normal assignments by maharshi_jd.pdf
Oops lab manual
AU exam
Chapter 3 Expressions and Inteactivity
Oops practical file
C++ Homework Help
CBSE Question Paper Computer Science with C++ 2011
Object Oriented Programming Using C++ Practical File
Practical File of c++.docx lab manual program question
14 operator overloading
Lecture05 operator overloading-and_exception_handling
Comp 220 ilab 6 of 7
(4) cpp automatic arrays_pointers_c-strings_exercises
Acm aleppo cpc training ninth session
Oops lab manual2
c++ lab manual

More from lksoo (13)

PDF
Lo43
PDF
Lo12
PDF
L10
PDF
L9
PDF
L8
PDF
L7
PDF
L6
PDF
L5
PDF
L4
PDF
L3
PDF
L2
PDF
L1
PDF
E6
Lo43
Lo12
L10
L9
L8
L7
L6
L5
L4
L3
L2
L1
E6

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PDF
advance database management system book.pdf
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction to Building Materials
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Hazard Identification & Risk Assessment .pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Trump Administration's workforce development strategy
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
IGGE1 Understanding the Self1234567891011
PDF
1_English_Language_Set_2.pdf probationary
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
Cell Types and Its function , kingdom of life
advance database management system book.pdf
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction to Building Materials
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Hazard Identification & Risk Assessment .pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Classroom Observation Tools for Teachers
Indian roads congress 037 - 2012 Flexible pavement
LDMMIA Reiki Yoga Finals Review Spring Summer
Trump Administration's workforce development strategy
UNIT III MENTAL HEALTH NURSING ASSESSMENT
IGGE1 Understanding the Self1234567891011
1_English_Language_Set_2.pdf probationary
Chinmaya Tiranga quiz Grand Finale.pdf
What if we spent less time fighting change, and more time building what’s rig...

P3

  • 1. COP3330 Programming Assignment 3 The bigint class Objective 1. Practice building class with operator overloading. Overview The native int type in C++ cannot store large integers of more than 10 decimal digits. In this project, you will implement a bigint class that behaves like the int type, but can handle unsigned integers of up to 45 digits. Details 1. You are to build a class named bigint that can deal with up to 45 decimal digits of unsigned integers. The bigint class is specified as follows. 2. The bigint class should have a five-element array (int v[5];) as its private date member. Each element should store 9 decimal digits. For example to store integer 1,300,000,000,000,900,000,000,100,000,000. You should have v[0] = 100000000, v[1] = 900000000, v[2] =0, v[3]= 1300, and v[4] = 0. 3. The bigint class should have the following constructors: bigint(); // default constructor, set the value to be 0 bigint(int x0); // set the value to be x0 bigint(int x0, int x1); // set the value to be x1*109+x0 bigint(int x0, int x1, int x2); // set the value to be x2*1018+x1*109+x0 bigint(int x0, int x1, int x2, int x3); bigint(int x0, int x1, int x2, int x3, int x4); 4. To make bigint behave like int, you must overload the following operators a. The extraction operator >> for reading a bigint number from an input stream. The input number can have up to 45 digits. Following are two legitimate bigint numbers that can appear as input: 1300000000000900000000100000000 9999999999999999999999999999999999999999999 b. The insertion operation << for output a bigint number to an output stream. The number must be output like a regular int number with the first digit being a non zero.
  • 2. c. 2 arithmetic operators + and – (*, and / are omitted for this type to simplify the program). d. 6 comparison operators <, >, <=, >=, ==, and !=. 5. Once the class is implemented, you can test your implementation using the proj3_driver.cpp program. You should also write other driver programs to do a thorough test of your bigint implementation. Put your bigint class declaration in proj3_bigint.h and your bigint class implementation in proj3_bigint.cpp. You should be able to compile the program by the command ‘g++ proj3_driver.cpp proj3_bigint.cpp’. Redirect proj3_test.txt as the standard input, the output of the program should be identical to proj3_test_out.txt. Submission The due time for this assignment is June 5 (Wendesday), 2013. 11:59pm. Tar all of your files for this assignment, which should include at least three files proj3_bigint.h, proj3_bigin.cpp, and bug_fixing_log.txt, name the tar file yourlastname_firstinitial_proj3.tar and submit the tar file in blackboard. The bug fixing log file must follow the template given in project 1. Grading policy The program must work on linprog. O point for programs with any g++ compiler error on linprog. You will need to track compiling errors that you fixed by yourselves in a log for fixed compiler bugs that needs to have at least two entries for 5 points/each entry (10 points max) that are different from those in the bug fixing log in projects 1 and 2. · Program with no compiler error (20 points) · Log for fixed compiler bugs (10 points) · The default constructor and the overloaded << operator (20 points) · Other four constructors (3 points each, 12 points total) · Six comparison operators (2 points each, 12 points total) · + and – operators (8 points each, 16 point total) · The >> operator (10 points) Hints 1. Start the project as soon as possible. 2. You should first create proj3_bigint.h and have an empty implementation in proj3_bigint.cpp for each member and friend function with the body of the function containing one line
  • 3. cout << “XXXX function has not been implemented.n” ; 3. You should then compile the proj3_bigint.cpp and proj3_driver.cpp and run the code. From here, you can implement and test one function after another until the whole class is implemented. 4. You should then implement the default construct, and write a simple operator<<() function that simply prints out the values of v[0], v[1], v[2], v[3], v[4]. 5. After that you can implement the functions in the following order: the << operator, other constructors, the comparison operators, the arithmetic operators, and the >> operator. Remember to compile and run the program at least once everytime you add one function. 6. To implement the << operator, you will need to output potentially 5 integers. You must use setw(9) and setfill(‘0’) to output each value besides the most significant non-zero integer. You must have ‘#include <iomanip>’ in the file in order to use these functions. The following line is an example to use these functions. s << setfile(‘0’) << setw(9) << vv.v[j]; 7. To implement the >> operator, you can first read the string of digits into a character array and then manually convert it into a bigint number. 8. To implement the + and – operators, you must pay special attention to the carry bit in the operations. 9. To see the prototype of the overloaded operators (+, ==, >>, <<), check the examples in lecture 6.