Question

•Write a program which control value of the robot. The charging min value is zero and...

•Write a program which control value of the robot. The charging min value is zero and max value is 100. When the charger is not plugged, the robot is in discharging state and the battery decreases. When charger is attached, the state is changed to charging and the value increase. Once it reaches the max
limit, the state changes to battery full.

Homework Answers

Answer #1

EXPLANATION:-

First checking if robot's charging plug is plugged or not if charging is plugged a function is called that will increase the charging by 1 and at each step it will also check if the charger is plugged or not , if charger is unplugged then another function that is made for discharging of battery is called and it will discharge the battery by one and if in between of discharging , charger is plugged then again charging function will be called like this it will go on.

CODE:-

#include<bits/stdc++.h>
using namespace std;
int current_charging_value = 0;
void charging_state(int charging);
void discharging_state(int charging)
{
   //this function is invoked when robot is not charging
   while(charging==0)
   {
       if(current_charging_value==0)//we'll stop discharging when it's charging value reaches to min
       {
           cout<<"Battery discharged";
           break;
       }
       current_charging_value-=1;//decrease in charging value
          
   }
   if(charging==1)
   charging_state(charging); // if charger is plugged then charging is started
}
void charging_state(int charging)
{
   //this function is invoked when robot is charging
   while(charging==1)
   {
   if(current_charging_value==100)//we'll stop charging when it's charging value reaches to max
       {
           cout<<"Fully charged";
           break;
       }
       current_charging_value+=1;//increase in charging value
   }
   if(charging == 0)
   discharging_state(charging); // if charger is unplugged then discharge is started
}
int main(){
int charging = 0;
char flg;
cout<<"Is the charger plugged?";
cout<<"Answer in Y/N ";
cin>>flg;
if(flg =='Y')
{
   charging = 1;//change in charging value if charger is pluged
}
else
{
   charging = 0;
}
discharging_state(charging);//if charging is 0 than the robot is in discharge state
charging_state(charging);//if charging is 1 than the robot is in charging state

}

OUTPUT:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Point/Counterpoint from chapter 14. Take a stand. Do you agree or disagree? Write a minimum of...
Point/Counterpoint from chapter 14. Take a stand. Do you agree or disagree? Write a minimum of one paragraph for each one. Chapter 14 Exporting E-waste: A Fair Solution? Point Yes Exporting is always and everywhere a win-win situation: The more companies and countries export, the more they improve market efficiency. Exporting enables companies to increase sales, improve productivity, and diversify activities. Likewise, exporting helps countries generate jobs, accelerate innovation, and improve living standards. In broader terms, it promotes connections among...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
What role could the governance of ethics have played if it had been in existence in...
What role could the governance of ethics have played if it had been in existence in the organization? Assess the leadership of Enron from an ethical perspective. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among the top Fortune 500 companies, collapsed in 2001 under a mountain of debt...
Discuss ethical issues that can be identified in this case and the mode of managing ethics...
Discuss ethical issues that can be identified in this case and the mode of managing ethics Enron finds itself in this case. How would you describe the ethical culture and levels of trust at Enron? Provide reasons for your assessment. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT