#include <iostream>
#include <cmath>
using namespace std;
class CounterType
{
public:
void set(int start_count, int number_to_count);
void get(int start_count, int number_to_count);
void update_positive();
void update_negative();
int get_count();
int get_counts_left();
void output(ostream& outs);
private:
int start_number;
int number_of_counts;
};
int main(){
CounterType counter;
int get_count, get_counts_left;
char ans;
cout << "If you would like to add a negative number of counts," << '\n';
cout << "Set number_to_count to negative" << '\n';
counter.set(0,0);
cout << "Lets start the count. The count is set to 0." << '\n';
counter.output(cout);
cout << '\n';
cout << "Enter the number for the counter to start on press enter. \n";
cout << "Then enter the number of counts you would like the counter to count. \n";
cout << '\n';
cin >> get_count >> get_counts_left;
cout << "Would you like to count up, or count down? \n";
cout << "Enter U or u for up and D or d for down. \n" << '\n';
cin >> ans;
if (ans == 'U' || ans == 'u'){
counter.update_positive();
}
else if (ans == 'D' || ans == 'd'){
counter.update_negative();
if (start_number <= 0){
cout << "This is not possible! \n";
counter = 0;
}
}
cout << "After the update, your count: \n";
counter.output(cout);
return 0;
}
void CounterType::get(int start_count, int number_to_count){
if (start_count < 0){
cout << "Your counter involves improper numbers." << '\n';
}
start_number = start_count;
number_of_counts = number_to_count;
}
void CounterType::set(int start_count, int number_to_count){
if (start_count < 0){
cout << "Your counter involves improper numbers." << '\n';
}
start_number = start_count;
number_of_counts = number_to_count;
}
void CounterType::update_positive(){
start_number = start_number + 1;
start_number = start_number + number_of_counts;
number_of_counts = 0;
}
void CounterType::update_negative(){
start_number = start_number - 1;
start_number = start_number + number_of_counts;
number_of_counts = 0;
}
int CounterType::get_count(){
return start_number;
}
int CounterType::get_counts_left(){
return number_of_counts;
}
void CounterType::output(ostream& outs){
outs.setf(ios::fixed);
outs.setf(ios::showpoint);
outs.precision(0);
outs << "The number after the count so far is: " << start_number << '\n';
outs << "The number of counts left is: " << number_of_counts << '\n';
}
The assignment we are to do is this:
Define a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a nonnegative whole number. Include a mutator function that sets the counter to a count given as an argument. Include member functions to increase the count by one and to decreast the count by one. Be sure that no member function allows the value of the counter to become negative. Also, invlude a member funciton that returns the current count value and one that ouputs the count. Embed your class definition into a test program.
I'm not seeing what is wrong here but it gives me these errors:
help9.cpp: In function ‘int main()’:
help9.cpp:58:7: error: ‘start_number’ was not declared in this scope
help9.cpp:60:13: error: no match for ‘operator=’ in ‘counter = 0’
help9.cpp:60:13: note: candidate is:
help9.cpp:7:7: note: CounterType& CounterType::operator=(const CounterType&)
help9.cpp:7:7: note: no known conversion for argument 1 from ‘int’ to ‘const CounterType&’
What is going wrong here??

New Topic/Question
Reply


MultiQuote


|