need help with this assignment, I use C++. Write a program to do the following: Use the same input seed data you used for Lab 4 (your BST homework) as seed input data into a hash table. Declare a hash table of size 29 elements. To hash your currency objects into the hash table, use the pseudorandom hash scheme - (m*w + n*f) % size - where size = 29, m = 2, n = 3, w = whole value, f = fractional value. For collision resolution, use quadratic probing in the same direction always. Remember to circle around to the start of the array if needed. Your main will first load the data file into the hash table and print the number of data items loaded, load factor and number of collisions. Then it will ask the user in a loop to enter a Dollar to search for. If the Dollar object is found in the hash table, it will print the index where found, otherwise it will print 'Invalid Data'. Then it will ask the user if they want to check again or end the program. To submit, upload your code files and screenshot of the console only. For documentation, only name blocks and existing documentation in your Dollar class are needed. Dollar Code: class Dollar : public Currency { private: string nameOfCurrency; public: Dollar(){ nameOfCurrency="dollar"; } Dollar( double value): Currency(value){ nameOfCurrency="dollar"; } //Prints function. void print() { cout << get_whole() << '.' << get_fraction() << " dollars" << endl; } }; Currency Code: class Currency { private: int whole; int fraction; public: int get_whole() { return whole; } int get_fraction() { return fraction; } void set_whole(int input_whole) { whole = input_whole; } void set_fraction(int input_fractional) { fraction = input_fractional; } Currency() { whole = 0; fraction = 0; } Currency(double input) { whole = int(input) ; fraction = (int)round(fabs(input - trunc(input)) * 1e2); } Currency(const Currency & p1) { whole = p1.whole; fraction = p1.fraction; } ~Currency() { } //Add method void add(double input) { whole = whole + int(input); fraction = fraction + (int)round(fabs(input - trunc(input)) * 1e2);; } //Subtract method void subtract(double input) { int whole_input = int(input); int fraction_input = (int)round(fabs(input - trunc(input)) * 1e2); if (whole-whole_input < 0 || fraction-fraction_input < 0) { cout << "Invalid subtraction" << endl; } else { whole = whole - whole_input; fraction = fraction - fraction_input; } } bool isEqual(Currency c1, Currency c2) { if (c1.whole == c2.whole){ if (c1.fraction == c2.fraction) return true; } return false; } bool isGreater(Currency c1, Currency c2) { if (c1.whole > c2.whole) return true; if (c1.fraction == c2.fraction) { if (c1.fraction > c2.fraction) return true; else return false; } return false; } void print() { cout << get_whole() << '.' << get_fraction() << endl; } }; Data: $57.12 $23.44 $87.43 $68.99 $111.22 $44.55 $77.77 $18.36 $543.21 $20.21 $345.67 $36.18 $48.48 $101.00 $11.00 $21.00 $51.00 $1.00 $251.00 $151.00 Thank you.
I need help with this assignment, I use C++.
Write a
- Use the same input seed data you used for Lab 4 (your BST homework) as seed input data into a hash table.
- Declare a hash table of size 29 elements.
- To hash your currency objects into the hash table, use the pseudorandom hash scheme - (m*w + n*f) % size - where size = 29, m = 2, n = 3, w = whole value, f = fractional value.
- For collision resolution, use quadratic probing in the same direction always. Remember to circle around to the start of the array if needed.
- Your main will first load the data file into the hash table and print the number of data items loaded, load factor and number of collisions.
- Then it will ask the user in a loop to enter a Dollar to search for. If the Dollar object is found in the hash table, it will print the index where found, otherwise it will print 'Invalid Data'. Then it will ask the user if they want to check again or end the program.
- To submit, upload your code files and screenshot of the console only.
- For documentation, only name blocks and existing documentation in your Dollar class are needed.
Dollar Code:
class Dollar : public Currency {
private:
string nameOfCurrency;
public:
Dollar(){
nameOfCurrency="dollar";
}
Dollar( double value): Currency(value){
nameOfCurrency="dollar";
}
//Prints function.
void print() {
cout << get_whole() << '.' << get_fraction() << " dollars" << endl;
}
};
Currency Code:
class Currency {
private:
int whole;
int fraction;
public:
int get_whole() {
return whole;
}
int get_fraction() {
return fraction;
}
void set_whole(int input_whole) {
whole = input_whole;
}
void set_fraction(int input_fractional) {
fraction = input_fractional;
}
Currency() {
whole = 0;
fraction = 0;
}
Currency(double input) {
whole = int(input) ;
fraction = (int)round(fabs(input - trunc(input)) * 1e2);
}
Currency(const Currency & p1) {
whole = p1.whole;
fraction = p1.fraction;
}
~Currency() {
}
//Add method
void add(double input) {
whole = whole + int(input);
fraction = fraction + (int)round(fabs(input - trunc(input)) * 1e2);;
}
//Subtract method
void subtract(double input) {
int whole_input = int(input);
int fraction_input = (int)round(fabs(input - trunc(input)) * 1e2);
if (whole-whole_input < 0 || fraction-fraction_input < 0) {
cout << "Invalid subtraction" << endl;
}
else {
whole = whole - whole_input;
fraction = fraction - fraction_input;
}
}
bool isEqual(Currency c1, Currency c2) {
if (c1.whole == c2.whole){
if (c1.fraction == c2.fraction)
return true;
}
return false;
}
bool isGreater(Currency c1, Currency c2) {
if (c1.whole > c2.whole)
return true;
if (c1.fraction == c2.fraction) {
if (c1.fraction > c2.fraction)
return true;
else
return false;
}
return false;
}
void print() {
cout << get_whole() << '.' << get_fraction() << endl;
}
};
Data:
- $57.12
- $23.44
- $87.43
- $68.99
- $111.22
- $44.55
- $77.77
- $18.36
- $543.21
- $20.21
- $345.67
- $36.18
- $48.48
- $101.00
- $11.00
- $21.00
- $51.00
- $1.00
- $251.00
- $151.00
Thank you.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 6 images