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

Create a new multifile project using the Resistor class developed in Week 1, and

ID: 3644459 • Letter: C

Question

Create a new multifile project using the Resistor class developed in Week 1, and include a new main() test function.



Create the Test Function Main() and the Support Function
Back to top

Create an array of pointers of type Resistor.
Use elements of the pointer array to allow the user to dynamically allocate memory and to instantiate objects of the Resistor class.
Use the indirect member-selection operator (pointer) in the test routine to access function members of the Resistor class.
Write a new, nonclass function called in function main() to sort the pointers to the Resistor objects in order from lowest nominal resistance value to highest, passing a pointer to the Resistor-object pointer as the only passed data argument.
Display the sorted Resistor objects according to the nominal resistance value, from lowest to highest.
Within the sorting function, use pointer arithmetic to access the individual Resistor objects.
Function main() should also ensure that there are no memory leaks when the program ends.

Here is the code that i have developed so far.

#include <iostream>
#include <ctime>
#include "stdafx.h"

using namespace std;

void Shuffle(bool baCardsDealt[]);
void PrintCard(int iCard);
int GetNextCard(bool baCardsDealt[]);
void PrintScoresAndHands(int iaHouseHand[], int iaPlayerHand[], const int CardCount,int PrintHand);

int main()
{
time_t qTime;
time(&qTime);
srand(qTime);

bool baCardsDealt[52];
int DealerCardCount = 0;
int DealerHand[12];
int PlayerCardCount = 0;
int PlayerHand[12];


// Loop once for each hand
while (true)
{
// "Shuffle" the cards; set them all to undealt
Shuffle(baCardsDealt);
// Deal the hands. Get two cards for each
PlayerHand[0] = GetNextCard(baCardsDealt);
DealerHand[0] = GetNextCard(baCardsDealt);
PlayerHand[1] = GetNextCard(baCardsDealt);
DealerHand[1] = GetNextCard(baCardsDealt);
DealerCardCount = 2;
PlayerCardCount = 2;

cout << " Tim Mathis Do3406648 " << endl;
cout << " Welcome to Tim's Blackjack Table " << endl ;
cout << " Would you like to play some Blackjack? " << endl;
cin >> " Yes(Enter Y) or No(Enter N) " >> endl;
//Here i have the program signaling for a new hand
cout << "New Hand" << endl;

//This is the initialization for the variables of drawing cards and so on
char cPlayerChoice;
bool bPlayerHits = true;
int iPlayerScore = ScoreHand(PlayerHand, PlayerCardCount);
// This will calculate the amount on the players cards for each hit.
do
{
//Here i have the program printing the dealt cards.
cout << "Dealers Cards" << endl;
cout << " ";
PrintCard(DealerHand[1]);
cout << endl;
cout << "Player's cards: Score = " << ScoreHand(PlayerHand, PlayerCardCount) << endl;
PrintHand(PlayerHand, PlayerCardCount);

//Here we sk the Player whether he wants a hit or to stay
cout << "Hit(press h) or stay(press s): ";
cin >> cPlayerChoice;
if (cPlayerChoice == 'h') {
PlayerHand[PlayerCardCount] = GetNextCard(baCardsDealt);
++PlayerCardCount;
} else if (cPlayerChoice == 's')
{
bPlayerHits = false;

cout << endl;
// This will get the players score and update itself to see if the player has a bust or not and can continue to play
iPlayerScore = ScoreHand(PlayerHand, PlayerCardCount);
} while (bPlayerHits && iPlayerScore < 22);

// Checks the players cards after being dealt to see if its a bust or not
if (iPlayerScore > 21)
{
// The Player busted. Dealer wins
cout << "The Dealer Wins!" << endl;
PrintScoresAndHands(DealerHand, DealerCardCount, PlayerHand, PlayerCardCount);
} else
{
// If the player didn't bust, the game will continue with the dealer
int iHouseScore = ScoreHand(DealerHand, DealerCardCount);
while (iHouseScore)
{
DealerHand[DealerCardCount] = GetNextCard(baCardsDealt);
++DealerCardCount;

}
bool bHouseBusts = (iHouseScore > 21);
if (bHouseBusts) {
// This lets us know if the dealer busted or not and says Player wins
cout << "The Player Wins!" << endl;
PrintScoresAndHands(DealerHand, DealerCardCount, PlayerHand, PlayerCardCount);
} else
{
// Takes readings on all the cards and deterimines if it was a tie or not
if (iPlayerScore == iHouseScore) {
// States if there was a tie to the user
cout << "Tie!" << endl;
PrintScoresAndHands(DealerHand, DealerCardCount, PlayerHand, PlayerCardCount);
} else if (iPlayerScore > iHouseScore)
{
// Tells the user the player won
cout << "Player Wins!" << endl;
PrintScoresAndHands(DealerHand, DealerCardCount, PlayerHand, PlayerCardCount);
} else {
//Tells the user that the dealer won
cout << "The Dealer Wins!" << endl;
PrintScoresAndHands(DealerHand, DealerCardCount, PlayerHand, PlayerCardCount);
}
}
}

return Exit;


void Shuffle(bool baCardsDealt[]) {
for (int Index = 0; iIndex < 52; ++Index) {
baCardsDealt[iIndex] = false;
}
}



void PrintHand(int Hand[], const int CardCount)
{
using namespace std;
for (int CardIndex = 0; CardIndex < CardCount; ++CardIndex) {
const int NextCard = Hand[CardIndex];
PrintCard(NextCard);
cout << " ";
}
cout << endl;
}

int GetNextCard(bool baCardsDealt[]) {
bool bCardDealt = true;
int NewCard = -1;
do {
NewCard = (rand() % 52);
if (!baCardsDealt[iNewCard]) {
bCardDealt = false;
}
} while (bCardDealt);
return NewCard;
}

int ScoreHand(int Hand[], const int CardCount) {
int AceCount = 0;
int Score = 0;
for (int CardIndex = 0; CardIndex < CardCount; ++CardIndex) {
const int NextCard = Hand[CardIndex];
const int Rank = (NextCard % 13);
if (Rank == 0) {
++AceCount;
++Score;
} else if (Rank < 9) {
Score = Score + (Rank + 1);
} else
{
Score = Score + 10;
}
}
while (AceCount > 0 && Score < 12)
{
--AceCount;
Score = Score + 10;
}
return Score;
}

void PrintScoresAndHands(int HouseHand[], const int DealerCardCount, int PlayerHand[], const int PlayerCardCount) {
using namespace std;

//Here the dealers score will be displayed
cout << "Dealer's Hand: Score = " << ScoreHand(HouseHand, DealerCardCount) << endl;
PrintHand(HouseHand, DealerCardCount);

//Here the players score will be displayed
cout << "Player's Hand: Score = " << ScoreHand(PlayerHand, PlayerCardCount) << endl;
PrintHand(PlayerHand, PlayerCardCount);
cout << endl;
}



Explanation / Answer

#include #include #include using namespace std; class ResistorClass { private: double m_dResValue; double m_dTolerance; double m_dMinResistance; double m_dMaxResistance; public: string m_cResistorName; void DisplayResistor( void ); void EnterResistance (void ); void AddSeries ( ResistorClass Resistor1, ResistorClass Resistor2 ); ResistorClass( ); ResistorClass( string Name, double nominalResistance, double Tolerance ); ResistorClass( const ResistorClass &ResistorObject ); ~ResistorClass( ); }; int main( void ) { ResistorClass oResOne; Resistor tolerance = 20% ResistorClass oResTwo("Resistor 2",4700,20); ResistorClass oResThree(oResTwo); oResOne.DisplayResistor(); oResTwo.DisplayResistor(); oResThree.DisplayResistor(); system("pause"); return 0; } void ResistorClass:: DisplayResistor ( void ) { cout
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