08 Jun must work in C++ with visual studios
Question
Objective: Create a C++ console application that utilizes the core concepts of inheritance and pointers by creating a class and a program that tests important features of that class.
Overview: This lab will require you to use C++ class inheritance to define and use a resistor class derived from a base resistor class. The program will allow the user to specify resistor component types and values.
You will be required to define a base class (ResistorClass) for a generic resistor device and a derived classes (FancyResistorClass) for specific resistor device type.
Resistor Class UML Diagram (# indicates a protected member):
Class: ResistorClass
# double *m_dptrRes
# char *m_sptrResName
+ int m_istResCounter (static)
+ void DisplayResistor(void)
+ void EnterResistance (void)
+ ResistorClass( )
+ ResistorClass(char Name[], double nominalResistance, double Tolerance)
+ ~ResistorClass( )
Begin work on this program by first coding the Resistor Class class declaration. Then code and test the Resistor class constructor functions one at a time. Code and test the rest of the functions one function at a time. To avoid compiler complaints, comment out the member function prototypes in the Resistor Class declaration that have not yet been completed.
specifications:
This is the default constructor.
* You will need to create two dynamic arrays using the new operator. The first array will store the resistor values (nominal, tolerance, min and max) and the second array (a character array) will hold the resistor’s name.
* The resistor array will have four elements. The values stored in the array will be of data type double. The values will be stored to the array in the following positions:
m_dptrRes[0] = the nominal resistance value
m_dptrRes[1] = the tolerance value
m_dptrRes[2] = the max resistance value
m_dptrRes[3] = the min resistance value
The nominal value should be initialized to 1000.0 and the tolerance value should be initialized to .10.
The minimum and maximum resistance should then be calculated using the nominal and tolerance variables. The formulas are:
Minimum Resistance = Nominal – Nominal * Tolerance
Max Resistance = Nominal + Nominal * Tolerance
* The user should be prompted to supply a name for the resistor. The value supplied by the user will be stored using the resistor’s name pointer. To conserve memory the name array should allocate only enough room to hold the number of characters supplied by the user. You’ll want the user’s entry to be saved to a string variable using the getline function. Then you’ll need to determine the number of characters in the string variable, allocate the required memory and copy the characters from the string variable to the pointer. This requirement is more for demonstration purposes than it is for practicality. Here is the essential code:
//get the user’s input
string Name;
getline(cin, Name);
//get the number of characters in the string
int length = (int)Name.length();
//add one to account for the null character
m_sptrResName = new char[length + 1];
//copy from Name to the pointer
strcpy_s(m_sptrResName, length + 1, Name.c_str());
The strcpy_s function performs a deep-copy of character array data. You could replace the strcpy_s function with a for/loop that performs a deep copy. The syntax for strcpy_s is as follows:
strcpy_s(char *Destination,
int numberOfElements,
char *Source);
* To keep count of the number of resistor objects in existence, be sure to increment the static variable m_istResCounter.
* Be sure to include an output statement that displays the message “Default Constructor Called”
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
