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 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 newRPM specifies 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
// C++ program to create and test Robot class
#include <iostream>
using namespace std;
class Robot
{
private:
double rpm, diameter;
public:
Robot();
void setRPM(double newRPM);
void setDiameter(double newDiameter);
double getRPM();
double getDiameter();
double getSpeed();
};
// default constructor
Robot::Robot() : rpm(74),diameter(1)
{}
//function to set the rpm
void Robot::setRPM(double newRPM)
{
// check if newPRM is valid, then set rpm to
newRPM
if(newRPM == 74 || newRPM == 190 || newRPM ==
265)
rpm = newRPM;
}
// function to set the diameter
void Robot::setDiameter(double newDiameter)
{
// check if newDiameter is valid, then set diameter to
newDiameter
if(newDiameter >= 1 && newDiameter <=
6)
diameter = newDiameter;
}
// function to return rpm
double Robot::getRPM()
{
return rpm;
}
// function to return diameter
double Robot::getDiameter()
{
return diameter;
}
// function to calculate and return speed in feet per
minute
double Robot::getSpeed()
{
double pi = 3.14159;
return((rpm *diameter*pi)/12);
}
int main() {
// test the class
Robot robot; // create an object of Robot class
// display the values after constructor
cout<<"Constructor:\nRPM
:"<<robot.getRPM()<<" Diameter :
"<<robot.getDiameter()<<" Speed :
"<<robot.getSpeed()<<endl;
// set the fields to valid values
robot.setRPM(190);
robot.setDiameter(5);
// display the values after setting to valid
values
cout<<"Setting RPM = 190 and diameter = 5:\nRPM
: "<<robot.getRPM()<<" Diameter :
"<<robot.getDiameter()<<" Speed :
"<<robot.getSpeed()<<endl;
// set the fields to invalid values
robot.setRPM(130);
robot.setDiameter(7);
// display the values after setting to invalid
values
cout<<"Setting RPM = 130 and diameter = 7\nRPM :
"<<robot.getRPM()<<" Diameter :
"<<robot.getDiameter()<<" Speed :
"<<robot.getSpeed()<<endl;
return 0;
}
//end of program
Output:
C++ Assignment 4 - Robot Speed Estimator Be sure to read through Chapter 7 Structured Data...
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...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
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...
C++
Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data about items in a retail store. Your submission should include 5 files, Retailltem.b, Retailltem.cpp, Store, Store.cpp, and Driver.cpp 1. Retailltem class: The class should have three member variables • description (a string, represent the item's name. A name contains space) quantity (an int, represent how many current available) price (a double, item's price) Member Functions Constructor with default argument get Description getQuantity getPrice setDescription...
In c++ Please. Now take your Project 4 and modify it. You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files. One (.h) file for the class definitions, both of them. The class implementation file which has the member function definitions. And the main project file where your main...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
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...
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...