Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This lab will explore the use of pointers in several ways. Pointers will be used

ID: 3637808 • Letter: T

Question

This lab will explore the use of pointers in several ways. Pointers will be used to dynamically allocate memory for new class objects on demand from the user, and they will be used to access class-member functions. Pointer arithmetic will be used to access and sort class objects according to criteria explained in the lab.

Pointers are, essentially, address variables, or variables that hold as their value the address of other variables. In terms of memory management, they are very powerful devices, and they more closely and efficiently use the actual internal hardware registers of the microprocessor that the program operates on.

Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.

The Resistor class created in the Week 2 lab will be used as the class that the pointer operations will be used upon. The lab also requires the use of accessor functions and static data members, which may be need to be added to the Resistor class definition and implementation.

I created this Resistor class in Week 2 lab:

// file Resistor.h
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Resistor
{
private:
string name;
double value;
double tolerance;
double minValue;
double maxValue;
public:
void DisplayResistor();
void GetResistance();
};
// file Resistor.cpp
#include "Resistor.h.



Explanation / Answer

#include #include #include #include #include #include using namespace std; const int MAX_RESISTORS = 50; class CResistor { private: double res_ohms; public: static int numResistors; CResistor(); double getResistance(); void setResistance(double resValue); }; COORD getXY(); void gotoXY(int nX, int nY); void delay(DWORD millisecs); #include "DynamicResistors.h" int CResistor::numResistors = 0; CResistor::CResistor() { } double CResistor::getResistance() { return 1.0; } void CResistor::setResistance(double resValue) { } void gotoXY(int nX, int nY) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD coordScreen; coordScreen.X = (SHORT) nX; coordScreen.Y = (SHORT) nY; SetConsoleCursorPosition( hConsole, coordScreen ); } COORD getXY( ) { COORD Coordinates; HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO *pBuffer = new CONSOLE_SCREEN_BUFFER_INFO; GetConsoleScreenBufferInfo(hConOut, pBuffer); Coordinates.X = pBuffer -> dwCursorPosition.X; Coordinates.Y = pBuffer -> dwCursorPosition.Y; delete pBuffer; return Coordinates; } void delay(DWORD millisecs) { MSG msg; DWORD endTick; endTick = GetTickCount() + millisecs; while(GetTickCount()
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote