Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

C++ class for a widget manufacturing plant that asks the user for the number of widgets that have been ordered and displays the number of days it will take to produce


 

Download  file 

Not a member!
Create a FREE account here to get access and download this file


 

Widget Factory
Design a C++ 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 rake 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 /lumber of widgets ordered.

Answer:




// Widget Factory
#include <iostream>
using namespace std;

// Declaration of the Widget class

class Widget
{
private:
   int   numHours;
   int   numShifts;
   int   widgetsPerHour;

public:
   // Consructor
   Widget() 
      { numShifts = 2; widgetsPerHour = 10; numHours = 8;}

   double daysToProduce(int);
};

//*************************************
// Constructor                        *
//*************************************

double Widget::daysToProduce(int widgets)
{
   double numDays = 
      static_cast<double>(widgets) / (numHours * numShifts * widgetsPerHour);
   return numDays;
}

//*************************************
// Function main                      *
//*************************************

int main()
{
   int    howMany;   // Number of widgets on order
   double days;      // Required number of days to produce
   
   // Create a Widget object.
   Widget factory;

   // Get the number of widgets on order.
   cout << "This program will calculate widget production time.\n";
   cout << "How many widgets are on order? "; cin >> howMany;
   
   // Validate the number of widgets.
   while (howMany < 0)
   {  
      cout << "Number must be 0 or greater. Please re-enter: "; cin >> howMany;
   }
   
   // Get the required number of days to produce
   // that many widgets.
   days = factory.daysToProduce(howMany);
   
   // Display the results.
   cout << "It will take " << days << " days to produce ";
   cout << howMany << " widgets.\n\n";

   return 0;
}






About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!