Assignment 4 - Robot Speed Estimator
Be sure to read through Chapter 7 Structured Data and Classes before starting this assignment. Your job is to write a program to estimate the speed of a robot. Your program will use a class called Robot to represent a robot. To keep things simple, this class will focus only on one aspect of a Robot - the maximum speed at which it can move.
Background
The speed of the robot is largely determined by two things - the speed of the gear motor and the size of the wheels that are mounted to the gear motors. The gear motor speed is typically measured in revolutions per minute (rpm). The wheel diameter will be measured in inches.
Here are some formulas and values that you will need:
|
pi |
= 3.14159 |
|
speed in inches per minute |
= rpm x wheel diameter x pi |
|
speed in feet per minute |
= speed in inches per minute / 12 |
Robot Class Description
Member Variables (also called data members)
Your class should have 2 floating-point member variables:
Your class should not have any other member variables. All member variables should be private.
Member functions
Your class should include member functions with the given prototypes and specifications. All the member functions described below should be public member functions. Do not do any input or output in any of your member functions.
Prototypes
Robot();
void setRPM(double newRPM);
void setDiameter(double newDiameter);
double getRPM();
double getDiameter();
double getSpeed(); |
Specifications
Your class should have a default (no argument) constructor called Robot that initializes the gear motor speed to 74 rpm and the wheel diameter to 1 inch.
Your class should have a mutator function (sometimes called a setter or set function). This function should be called setRPM. This function allows the user to change the gear motor speed of the robot. The parameter newRPMspecifies the new value for the gear motor speed. The new speed must be one of these speeds: 74, 190 or 265 RPM. All other values are invalid. If newRPM contains a valid value, store the information from the parameter into the member variable that represents the speed (rpm) of the gear motor. Otherwise, do not update the member variable (do nothing).
Your class should have a set member function called setDiameter that allows the member variable that stores the wheel diameter to be updated. The parameter newDiameter specifies the new value for the wheel diameter in inches. The new diameter must be one inch or larger and six inches or smaller. Another way to say this is that the new diameter must be in the range 1 to 6 inches inclusive. If newDiameter is valid, store the new diameter in the member variable for the wheel diameter. Otherwise, do nothing (do not update the member variable).
Your class should have an accessor (or getter or get) member function called getRPM. This function should return the speed of the gear motor in revolutions per minute.
Your class should have a get member function called getDiameter that returns the diameter of the robot's wheel in inches.
Your class should have a get member function called getSpeed that returns the speed of the robot in feet per minute.
Testing
Write a main function to test your class. Be sure that your output shows that each of your member functions works correctly.
Other Requirements
Source Code in C++:
#include <iostream>
using namespace std;
class Robot
{
private:
double rpm,diameter; //instance variables
public:
Robot() //default constructor
{
this->rpm=74;
this->diameter=1;
}
void setRPM(double newRPM) //setter method for member rpm
{
if(newRPM==74 || newRPM==190 || newRPM==265)
this->rpm=newRPM;
}
void setDiameter(double newDiameter) //setter method for member
diameter
{
if(newDiameter>=1 && newDiameter<=6)
this->diameter=newDiameter;
}
double getRPM() //getter method for member rpm
{
return this->rpm;
}
double getDiameter() //getter method for member diameter
{
return this->diameter;
}
double getSpeed() //method to calculate and return speed of robot
in feet per minute
{
const double PI=3.14159;
return this->rpm*this->diameter*PI/12;
}
};
int main()
{
//testing the class
Robot r;
r.setRPM(190);
r.setDiameter(4);
cout << "Robot RPM: " << r.getRPM() <<
endl;
cout << "Robot Diameter: " << r.getDiameter() <<
" inches" << endl;
cout << "Robot Speed: " << r.getSpeed() << " feet
per minute" << endl;
return 0;
}
Output:

Assignment 4 - Robot Speed Estimator Be sure to read through Chapter 7 Structured Data and...
C++ Assignment 4 - Robot Speed Estimator Be sure to read through Chapter 7 Structured Data and Classes before starting this assignment. Your job is to write a program to estimate the speed of a robot. Your program will use a class called Robot to represent a robot. To keep things simple, this class will focus only on one aspect of a Robot - the maximum speed at which it can move. Background The speed of the robot is largely...
In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...
Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...
Object Oriented Programming
Please write the code in C++
Please answer the question in text form
9.5 (complex Class) Create a class called complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form where i is V-I Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...
Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...
power = 3 kW
if need any more information please ask !!!
You are the designer and you have been asked to design a speed reducer (gearbox) that will take power from the shaft of an electric motor rotating at 1500 rpm and deliver it to a machine that is to operate at approximately at 200 rpm Assume that you have decided to use spur gears to transmit the power [A power equal to the last one digits of your...
So far I have this code but
I'm not sure if it's right or how to finish it.
#include "distance.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
Distance::Distance()
{
feet = 0;
miles = 0;
yards = 0;
inches = 0;
}
Distance::Distance(int inch)
{
}
Distance::Distance(int m, int y, int f, double i)
{
if(m < 0 || y < 0 || f < 0)
{
feet = 0;
miles = 0;
yards = 0;
}...
Write a C++ program for the instructions below. Please
read the instructions carefully and make sure they are followed
correctly.
and please put comment with code!
Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...
C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.] Write a rational number class. Recall that a rational number is a ratio-nal number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects...