Modify the Resistor-Class Definition Back to top Add a static data member of the
ID: 3644458 • Letter: M
Question
Modify the Resistor-Class DefinitionBack to top
Add a static data member of the class Resistor to keep track of the number of Resistor objects that are dynamically created. This will also be used to limit the number of objects that are dynamically created to the maximum array size of the pointer array in the test function main().
In the Resistor constructor, use a random-number generator to randomly assign a nominal resistance value to the object between 1,000 and 10,000 ohms. The resistance values are not required to be standard resistance values.
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 ) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.