Question
in c++ Do not change the main or any the function signature of any of the functions Ive given you. You can only use stack,
in c++
Do not change the main or any the function signature of any of the functions Ive given you. You can only use stack, linked list or queus.
only work were it says "TODO" and you're allowed to add more libraries if needed
My main:
#include "bignum_calculator.h"
#include
#include
#include
#include
#include
typedef bignum_calculator::bignum bignum; int main(int argc, char **argv) { if (argc != 3) { std::cout << "You need 2 arguments: an input file and an output file"; return -1; //a non-zero means there was an error in execution } bignum_calculator *bc = new bignum_calculator(); std::ifstream reader(argv[1]); std::ofstream writer(argv[2]); std::string op; std::string num_1; std::string num_2; std::string line; while (std::getline(reader, line)) { std::istringstream line_splitter(line); //not best practice as it assumes properly formatted input but alas line_splitter >> op; line_splitter >> num_1; line_splitter >> num_2; //important to create bignums in here so they get reset every iteration bignum bignum_1; bignum bignum_2; bignum res; bc->str_to_bignum(num_1, &bignum_1); bc->str_to_bignum(num_2, &bignum_2); if (op == "add") { bc->add(bignum_1, bignum_2, &res); writer << num_1 << " + " << num_2 << " = "; writer << bc->bignum_to_str(res) << " "; } else if (op == "multiply") { bc->multiply(bignum_1, bignum_2, &res); writer << num_1 << " * " << num_2 << " = "; writer << bc->bignum_to_str(res) << " "; } else { std::cout << "Can only add or multiply, please check input file formatting and spelling."; return -1; } } return 0; }
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
bignum_calculator.cpp: #include "bignum_calculator.h" typedef bignum_calculator::bignum bignum; bignum_calculator::bignum_calculator() { //nothing to do here } bignum_calculator::~bignum_calculator() { //nothing to do here } void bignum_calculator::str_to_bignum(std::string str, bignum *num) { //TODO } bool bignum_calculator::compare_bignum(bignum num_1, bignum num_2) { //TODO } std::string bignum_calculator::bignum_to_str(bignum num) { //TODO } void bignum_calculator::add(bignum num_1, bignum num_2, bignum *sum) { //TODO } void bignum_calculator::multiply(bignum num_1, bignum num_2, bignum *product) { //TODO }
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
bignum_calculator.h:
#include #ifndef BIGNUM_CALCULATOR_H #define BIGNUM_CALCULATOR_H class bignum_calculator { public: //used to represent bignum numbers. a bignum is a number in reverse order //i.e., the real number 1234 would be the bignum 4,3,2,1 typedef TODO bignum; //TODO: choose the appropriate data structure to represent a bignum //default constructor, needs no args bignum_calculator(); //default destructor ~bignum_calculator(); //converts the number in str to a bignum and stores it in num void str_to_bignum(std::string str, bignum *num); //returns true if both bignums are the same, false otherwise bool compare_bignum(bignum num_1, bignum num_2); //converts the bignum number to a string and returns the value of said string std::string bignum_to_str(bignum num); //sums num_1 and num_2 and stores the result in sum void add(bignum num_1, bignum num_2, bignum *sum); //multiplies num_1 and num_2 and stores the result in product void multiply(bignum num_1, bignum num_2, bignum *product); }; #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started