please give me an answer... Do not just paste and copy my format. please read comment.
#include <lab46.h>
using namespace std;
int main(){BigInt a, b;
while (cin >> a >> b){cout << a << " + " << b << " = " << a + b << endl;cout << a << " - " << b << " = " << a - b << endl;cout << b << " - " << a << " = " << b - a << endl;}
cout << endl;cout << "Fibonacci Sequence" << endl;BigInt i(1), end(51), first(1), second(1);
while (i < end){cout << "Fib(" << i << ") = " << first << endl;second = first + second;first = second - first;i = i + 1;}
return EXIT_SUCCESS;}----------------------------------------------------------------------------
#ifndef LAB46_H#define LAB46_H
#include <iostream>#include <string>#include <deque>
using namespace std;
typedef enum {NEGATIVE, ZERO, POSITIVE} Sign;
bool isInt(string s);
class BigInt{friend ostream& operator<<( ostream& output, const BigInt& );friend istream& operator>>( istream& input, BigInt& );public:BigInt(); // constructor; digits = 0BigInt( int num ); // constructor; digits = numBigInt( const string str ); // constructor; digits = strBigInt( const BigInt& other ); // copy constructor
bool operator==( const BigInt& rhs ) const; // Equalitybool operator< ( const BigInt& rhs ) const; // Less Than
BigInt operator+ ( const BigInt& rhs ) const; // AdditionBigInt operator- ( const BigInt& rhs ) const; // Subtraction
private:Sign sign; // Sign of #deque<char> digits; // Deque of digits of #};
#endif--------------------------------------------------------------------------------------
#include <lab46.h> //How can writhe code in this page?
BigInt BigInt::operator+ ( const BigInt& rhs ) const // Addiction{if (rhs.sign == ZERO)return *this;else if (this->sign == ZERO)return rhs;else if (this->sign == rhs.sign){ // both signs are NEGATIVE or both are POSITIVE, so addBigInt sum;//...return sum;}else{ // signs are different, one is NEGATIVE and one is POSITIVE, so subtractBigInt difference;//..return difference;}}
Lab 46 Source File: Input: Output: Value: Extend the BigInt class from Lab 45 to provide overloaded operators for performing addition and subtraction with BigInt numbers. A header file is shown in Figure 1, a sample main function for testing your implementation is shown in Figure 2, and a sample execution sequence is shown in Figure 3. To use the Makefile as distributed in class, add a target of lab46 to targets2srcfileswithlibrary. 3 11 12 24 27 1 #ifndef LAB46_H #define LAB46_H 2 10 3 11. 36 12 4 #include 5 #include 6 #include 13 55 8 using namespace std; 9 15 57 14 class BigInt { 16 17 61 18 19 Lab 46 20 Page 2 21 Lab 46 22 23 24 25 26 27 28 29 30 31 33 34 35 /2336/46/1ab46. (CICPP|cpp|c++|cc|cxx|cp) Under control of main function Under control of main function 5 CS 2336 Data Structures and Algorithms typedef enum {NEGATIVE, ZERO, POSITIVE) Sign; bool isInt (string s); friend ostream& operator<<(ostream& output, const BigInt& ); friend istream& operator>>(istream& input, BigInt& ); public: }; BigInt (); BigInt(int num ); BigInt( const string str); BigInt( const BigInt& other ); Lab 46 Page 4 private: Lab 46 bool operator==(const BigInt& rhs) const; // Equality bool operator< (const BigInt& rhs) const; // Less Than BigInt operator+(const BigInt& rhs) const; // Addition BigInt operator- (const BigInt& rhs) const; // Subtraction Sign sign; deque digits; #endif 3 using namespace std; 7 5 int main() { 8 9 10 13 14 140 15 16 17 20 22 23 24 25 26 27 #include 29 } Figure 1. /usr/local/2336/include/lab46.h BigInt a, b; while (cin >> a >> b) { newuser@csunix > cd 2336 newuser@csunix /2336> ./getlab.ksh 46. * Checking to see if a folder exists for Lab 46. . .No * Creating a folder for Lab 46 * Checking to see if Lab 46 has sample input and output files. . .Yes 6 * Copying input and output files for Lab 46 * Checking to see if /usr/local/2336/src/lab46main.C exists. . .Yes 9 * Copying file /usr/local/2336/src/lab46main. C to folder ./46 * Checking to see if /usr/local/2336/include/lab46.h exists. . .Yes * Copying file /usr/local/2336/include/lab46.h to folder ./46 * Copying file /usr/local/2336/src/Makefile to folder ./46 13 * Adding a target of lab46 to targets2srcfileswithlibrary * Touching file ./46/lab46.cpp 25 -12345678901234567890. while (i < end) { } cout << endl; cout << "Fibonacci Sequence" << endl; BigInt i(1), end (51), first (1), second (1); 15 *Edit file ./46/lab46.cpp in Notepad++ 16 newuser@csunix /2336> cd 46 17 newuser@csunix /2336/46> 1s 18 01.dat 01. out Makefile 19 newuser@csunix /2336/46> make lab46 20 g++ -g -Wall -std=c++11 -c lab46main. C -I/usr/local/2336/include -I. 21 g++ -g -Wall -std=c++11 -c lab46.cpp -1/usr/local/2336/include -I. 22 g++ -o lab46 lab46main.o lab46.o -L/usr/local/2336/1ib \ 23 -W1, -whole-archive -llab46 -W1, -no-whole-archive -lm-lbits cout << a << " + " << b << " = " << a + b << endl; cout << a << " b << endl; " << b << " = cout << b << " - " " << a << b a << endl; } return EXIT_SUCCESS; from folder /usr/local/2336/data/46 to folder ./46 newuser@csunix /2336/46> cat 01. dat 28 29 12345678901234567890-12345678901234567890 30 12345678901234567890 cout << "Fib(" << i << ") = " << first << endl; second first + second; first second first; i=i+1; Figure 2. /usr/local/2336/src/lab46main.C 32 -98765432109876543210 -12345678901234567890 33 -9999999999999999999999999999999999999998 34 -99999999999999999998 -99999999999999999999 -1234567890123456789 0 -1234 -1234567890123456789 37 12345678901234567890 12345678901234567890 -1 +0 -12345678901234567890 -0 12345678901234567890 lab46.cpp lab46.h 0 Fib (9) = 34 141 Fib(10) 55 142 Fib(11) 89 143 Fib(12) 144 51 newuser@csunix /2336/46> cat 01. dat ./lab46 52 -12345678901234567890+ 0 = -12345678901234567890 CS 2336 Data Structures and Algorithms 0 0 53 -12345678901234567890 012345678901234567890 54 0 -1234567890123456789012345678901234567890 -1 + 1 = 0 56 -1 -1 = -2 1 -1 = 2 -1234 // constructor; digits = 0 // constructor; digits = num // constructor; digits = str // copy constructor 38 012345678901234567890 -12345678901234567890 59 01234567890123456789012345678901234567890 60 -12345678901234567890 012345678901234567890 41 42 43 Due Date: See Blackboard // Sign of # // Deque of digits of # 47 50 0 + 1234567890123456789012345678901234567890 012345678901234567890-12345678901234567890 63 12345678901234567890012345678901234567890 64 12345678901234567890+ -12345678901234567890 = 0 65 12345678901234567890-12345678901234567890 = 24691357802469135780 184 CS 2336 Data Structures and Algorithms Due Date: See Blackboard. Due Date: See Blackboard lab46main. C 12345678901234567890 98765432109876543210 98765432109876543210 12345678901234567890 1234567890123456789 Figure 3. Commands to Compile, Link, & Run Lab 46 (Part 1 of 3) CS 2336 toótob 66 -1234567890123456789012345678901234567890 = -24691357802469135780 67 12345678901234567890+ 0 = 12345678901234567890 68 12345678901234567890012345678901234567890 69 012345678901234567890-12345678901234567890 70 0+ 0 = 0 71 000 72 0 0 0 73 -98765432109876543210 + -12345678901234567890 = -111111111011111111100 74 -98765432109876543210-12345678901234567890= -86419753208641975320 75 -12345678901234567890-98765432109876543210 = 86419753208641975320 76 -9999999999999999999999999999999999999998-199999999999999999997 -99999999999999999999 -99999999999999999998 = -1 = 1 1234 1234567890123456789 -0 0 +0 78 -99999999999999999998-99999999999999999999 79 -99999999999999999998 +-99999999999999999999 = -199999999999999999997 80 -99999999999999999998 -99999999999999999999 = 1 81 -9999999999999999999999999999999999999998 = -1 82 -1234567890123456789 + -1234 = -1234567890123458023 83 -1234567890123456789--1234 = -1234567890123455555 -1234-1234567890123456789= 1234567890123455555 85 -1234-1234567890123456789= -1234567890123458023 86 -1234-1234567890123456789 = 1234567890123455555 87 -1234567890123456789 -1234 = -1234567890123455555 88 12345678901234567890+ 12345678901234567890 = 24691357802469135780 89 1234567890123456789012345678901234567890 = 0 90 1234567890123456789012345678901234567890 = 0 91 12345678901234567890+ 98765432109876543210 111111111011111111100 92 12345678901234567890 98765432109876543210 -86419753208641975320 93 98765432109876543210 12345678901234567890 = 86419753208641975320 94 98765432109876543210 + 12345678901234567890 111111111011111111100 95 98765432109876543210 12345678901234567890 86419753208641975320 96 12345678901234567890 98765432109876543210 = -86419753208641975320 97 1234567890123456789+1234 = 1234567890123458023 98 12345678901234567891234 = 1234567890123455555 99 1234 1234567890123456789= -1234567890123455555 100 1234 1234567890123456789= 1234567890123458023 101 1234 1234567890123456789 = -1234567890123455555 102 12345678901234567891234 = 1234567890123455555 Figure 3. Commands to Compile, Link, & Run Lab 46 (Part 2 of 3) Page 1 103 0+ 0 0 Fib(13) 233 104 0-0 =0 145 Fib(14) 377 105 00: 0 146 Fib(15) 610 106 0+0=0 147 Fib(16) 987 107 0 0 0 148 Fib(17) 1597 108 0 0 0 149 Fib(18) 2584 109 0+ 0 = 0 150 Fib(19) 4181 110 0 0 0 151 Fib (20) 6765 111 0-0 =0 152 Fib(21) 10946 112 0+ 0 = 0 153 Fib(22) 17711 113 0 0 0 154 Fib(23) 28657 114 0 0 0 155 Fib(24) 46368 115 0 + 0 = 0 156 Fib(25) 75025 116 0-0 =0 157 Fib(26) 121393 117 0 0 0 158 Fib(27) 196418. 118 0 + 0 = 0 159 Fib(28) 317811 119 0 0 = 0 160 Fib(29) 514229 120 0 0 0 161 Fib(30) 832040 IT 121 0 + 0 = 0 162 Fib(31) 1346269 122 0 163 Fib(32) 2178309 123 0 0 0 164 Fib(33) 3524578 124 0+ 0 = 0 165 Fib(34) 5702887 125 0 0 0 166 Fib(35) 9227465 126 0 0 0 Fib(36) 14930352 127 0 + 0 = 0 168 Fib(37) 24157817 128 0 0 0 169 Fib (38) 39088169 129 0 0 0 170 Fib(39) 63245986. 130 Fib (40) = 102334155. 131 Fibonacci Sequence 172 Fib(41) 165580141 132 Fib (1) 1 173 Fib(42) 267914296 133 Fib (2) 1 174 Fib (43) 433494437 134 Fib(3) = 2 175 Fib(44) 701408733 135 Fib (4) = 3 176 Fib(45) 1134903170 136 Fib (5) = 5 177 Fib(46) 1836311903. Fib (6) 8 Fib(47) 2971215073 138 Fib (7) 13 179 Fib(48) 4807526976 139 Fib (8) 21 180 Fib(49) 7778742049 Fib(50) 12586269025 1234 182 newuser@csunix /2336/46> cat 01.dat ./lab46> my.out 183 newuser@csunix /2336/46> diff 01.out my.out newuser@csunix /2336/46> -0 Figure 3. Commands to Compile, Link, & Run Lab 46 (Part 3 of 3) ttt...óóó -0 Due Date: See Blackboard -0 0 0 +0 +0 Data Structures and Algorithms Page 3 Due Date: See Blackboard
please give me an answer... Do not just paste and copy my format. please read comment. #include using namespac
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am