Question: CSIS 211 C++ hoemworks coding fix. Make sure please write the coding in C++ in multiply classes when solving my problem of the coding. I

CSIS 211 C++ hoemworks coding fix.

Make sure please write the coding in C++ in multiply classes when solving my problem of the coding.

I need help to find a way to put the file coding of steps 3 in my coding for the File-O. I have a hard time figure out how to solve the errors of my coding. Can you please check my coding to see if you can fix my coding base upon steps three and steps four. Explain to me how you solve for steps 3 and steps four.

Instruction:

steps 1: summary to create a char classess

steps 2: create a Bigdecimal classess

Step 3 File IO

Make a change to your BigDecimal class to add the following functions (methods)

  • int wholeNumber() - Returns only the whole number portion of the decimal number as an int
  • double fraction() - Returns the fractional portion of the number as double

File IO

Attached at this link is a text file called Numbers.txt that contains several numbers. You are to read in each of these numbers and store them in your BigDecimal class. Basically you are going to need a BigDecimal class for each number that is in the file. Store each BigDecimal in some kind of container like a vector or an ArrayList.

Once you have all of the numbers loaded use a loop to write out all of the numbers into two separate text files. One file called wholeNumbers.txt will hold the whole number portion of the number. The other file call fraction.txt will hold the fractional portion of the number. Make sure you include the decimal point.

Open each of the files in Notepad and make sure that you have one number per line.

Numbers.txt:

29.06367626098403

42.77383737710885

Step 4 Exceptions

Create an exception class called CharException to be thrown in the equals function that takes an int as a parameter. You should check the range of the int to make sure it is a valid readable character. Basically if the parameter is less than 32 or greater than 127 you want to throw a CharException with the message "Invalid Character".

C++

Use public inheritance to derive your CharException class from exception. Override the virtual function what (const char *what()) so that it returns the message "Invalid Character". Use the what function to display the error message. Below is and image of main and it's output to give you an idea of how the class should work:FinallyCreate a BigDecimalException class that is derived from the CharException class. You should throw this exception anytime that a character is being set that is not a valid character (a digit or a decimal). You should also throw this exception if more than one decimal is being set.At this point I am not going to give you many specifics on how to implement this. I will only say that you are to use inheritance. No matter how you implement this class please have good reasoning for doing so. It is time for all of us to start using what we have learned to formulate our own ideas.Important:For this assignment I expect that you will use good coding practices. This means that whenever possible you should create one code path. Having code duplications will be frowned upon and may result in a point reduction in your grade.

 

Here is my coding:

#include #include "Char.h" #include "CharException.h" #include "BigDecimal.h" #include "BigDecimalException.h"

using namespace std;

int main() { Char ch('A'); Char c('B');

cout << ch.add(c) << endl; cout << ch.toChar() << " In Hex: " << ch.toHexString(); cout << ch.toChar() << " In Decimal " << ch.toInt();

try { cout << "Try to set 140 as character" << endl; ch.equals(140); cout << ch.toChar() << endl; } catch (CharException * ce) { cout << ce->what() << endl; } return 0;

}

/// File: Char.H /// Author: Matthew /// Student id: 0567997 /// Description: Assignment 6. /// Date: 2/27/2021 /// #ifndef char_H_ #define char_H_ #include #include using std::string;

class Char { public:

//constructors int data; Char(); //default constructor that sets the data sections Char(char c); //overloard constructors taht takes privatory Char(int c); // overloaded constructor that takes a primitive int as a parmeter. the data section of the class Char(const Char& c); //overload construcro thattakes complex chartype as a parameters. The data section of class should be set with the data section of the argument Char(string c);

//mutators void equals(const Char& c); //set the data section of the argument void equals(char c); // sets the data section to the primitive arugment void equals(int c); // sets the data section of the class as a character from the int argument

//Accessor functions char toChar() const; //Return the data section of the classs a char. int toInt() const; // Returns the data section of the class as an int. string toString(); //Returns the data section of the class as a string string toHexString(); //Returns the data section of the class as a hexadecimal valued string string add(char c); //Concatenates the data section of the class with the parameter and returns the two characters as a string. string add(const Char& c); //Concatenates the data section of the class with the data section of the parameter and returns the two characters as a string. }; #endif

/// File: Char.cpp /// Author: Matthew /// Student id: 0567997 /// Description: Assignment 6. /// Date: 2/27/2021 /// #include "Char.h" #include #include using std::string; using namespace std;

Char::Char() { data = '\0'; } Char::Char(char c) { data = c; } Char::Char(int c) { data = (int)c; } Char::Char(const Char& c) { data = c.data; } Char::Char(string c) { data = c[0]; } void Char::equals(const Char& c) { data = c.data; } void Char::equals(char c) { data = c; } void Char::equals(int c) { data = (char)c; } char Char::toChar() const { return data; } int Char::toInt() const { return (int)data; } string Char::toString() { string str = "a"; str[0] = data; return str; } string Char::toHexString() { char* l_pCharRes = new (char); itoa((int)data, l_pCharRes, 16); return l_pCharRes; } string Char::add(char c) { string str = "ab"; str[0] = data; str[1] = c; return str; } string Char::add(const Char& c) { string str = "ab"; str[0] = data; str[1] = c.data; return str; }

/// /// File: BigDecimal.h #ifndef bigdecimal #define bigdecimal #include #include using std::string;

int v; class BigDecimal { public: std::vector data;

//constructors BigDecimal(); //default constrout simple set the contianer three char object that contain the values '0'.'0' BigDecimal(string value); //This constructor will parse the sgtring taking each digit, putting it into a new char and adding the char to the container

//mutators void equals(char ch); void equals(string value); BigDecimal add(BigDecimal); BigDecimal sub(BigDecimal);

//Accessors double toDouble(); string toString(); char at(int index);

};

#endif

#include "BigDecimal.h" #include "BigDecimalException.h" #include "Char.h" #include #include #include #include using std::string;

BigDecimal::BigDecimal() { Char data1('0'); Char data2('.'); Char data3('0'); data.push_back(data1); data.push_back(data2); data.push_back(data3); } BigDecimal::BigDecimal(string value) { int i = 0; while (value[i] != '\0') { Char c(value[i]); data.push_back(c); i++; } /*for(i = 0; i < 3; i++){ cout << data[i].toChar() << endl; }*/ } void BigDecimal::equals(char ch) { if (ch >= '0' && ch <= '9') data[0].equals(ch); } void BigDecimal::equals(string value) { //if(isdigit(ch)) //data[0].equals(value); } double BigDecimal::toDouble() { } Char BigDecimal::at(int index) { return data[index]; } string BigDecimal::toString() { int size = data.size(); char str[size]; int i = 0; for (i = 0; i < size; i++) str[i] = data[i].toChar(); return str; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!