class programming

Hello everyone I had a question and I'm stumped. This is a question I need help on and so far what i have down i'm getting errors.

Design a class for a widget manufacturing plant. Assuming that 10 widgets may be produced each hour, the class object will calculate how many days it will take to produce any number of widgets. (The plant operates two shifts of eight hours each per day.) Write a program that asks the user for the number of widgets that have been ordered and then displays the number of days it will take to produce them.
INPUT VALIDATION: DO NOT ACCEPT NEGATIVE VALUES FOR THE NUMBER OF WIDGETS ORDERED.

what i hav eso far is this::::::>>>>>>>>>>>>>


#include <iostream>
using namespace std;


class widget
{
private:
double now;
double nod;
public:
void setWidgets(double w)
{
if(w>0)
{
now=w;
nod=now/160;
}
else
cout<<"Invalid number of widgets"<<endl;
}

double getwidgets()
{
return nod;
}
};

int main()
{
widget w;

double d;

cout<< "Enter the number of widgets"<<endl;
cin>> d;
w.getWidgets(d);

cout<< "The number of days it takes to produce " << d<< "widgets is: " << w.getwidgets(d)<<endl;
return 0;
}
Well your off to a good start. I will say a few things about your variable types and methods. Firstly, if it doesn't make sense to have a fraction of a widget, then by all means make the widget count an integer. e.g.
1
2
//double now;
int now;


For your methods, practicing on making them do what they are intuitively named for. For example, you did well with setWidgets, however, getwidgets doesn't do what you think it would do. Change getwidgets to return now the number of widgets. Make a new method called something like getDaysToProduce or whatever you think is appropriate.

As far as your errors, you don't mention what errors you are getting but when you make the call to w.getwidgets(d) the signature for your method takes no parameters but you are trying to pass the number of widgets into it.
Topic archived. No new replies allowed.