Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

RLC Circuits Use the following PhET simulation to complete the experiment. Include this document, figures, and typed summary (Part 4) in your submission....

1 answer below »
RLC Circuits
Use the following PhET simulation to complete the experiment. Include this document, figures, and typed summary (Part 4) in your submission.
https:
phet.colorado.edu/en/simulation/circuit-construction-kit-ac-virtual-la
Part 1 – LC Circuit
1. Create a circuit with a battery and a capacitor inseries to charge the capacitor. Right click the capacitor, click Change Capacitance, and note down the capacitance.
2. Press pause at the bottom of the screen and disconnect the battery and remove it from the simulation.
3. Connect an inductor in series with the capacitor. Right click the inductor, click Change Inductance, and write down the inductance. Press play a
ow. Note any observations you see.
4. Click Cu
ent Chart and place the detector on a wire in the circuit between the capacitor and inductor. Adjust the y-axis using the +/- a
ows so that you can see the full sinusoidal curve and maximum cu
ent. Note the maximum/minimum cu
ent. To your best ability write down the period between maximum peaks.
5. Using the inductance and capacitance values you write down calculate the resonant frequency ω0 = 1
√LC. Covert the period you measured in #4 to an angular frequency ω = 2π / Period. How do ω0 and ω relate?
6. Click Voltage Chart and place the detectors on either side of the capacitor. Add a second chart on both sides of the inductor. Make sure the polarity of the detectors is consistent. Adjust the y-axis using the +/- a
ows so that you can see the full sinusoidal curve and maximum voltage on each graph. Qualitatively note the similarities and differences between the curves. Not the maximum/minimum voltages. To your best ability write down the period between maximum peaks.
7. Screen grab your circuit and include the picture in your lab report. Save the circuit for your own records.
Part 2 – RLC Circuit
1. Create a circuit with an AC Voltage in series with a resistor, inductor, and capacitor. Note also the capacitance, inductance, and resistance as was done in Part 1.
2. Right click the AC Voltage and click Change Voltage and note the cu
ent value of the voltage. Click Change Frequency and note the cu
ent value of frequency.
3. Place Voltage Chart around each element in the circuit, include the AC Voltage. Make sure the polarity is consistent.
4. Mark the maximum/minimum voltage on each graph. Qualitatively note the similarities and differences between the graphs. Which graphs are in phase with one another? Which graphs are not? What about the sign of the amplitude?
5. Using the RMS voltages (VRMS = V0 / √2) show that the RMS voltage on the AC Voltage is consistent with the voltage sum of each element VRMS = √ [ (VRMS,R)^2 + (VRMS,L -VRMS,C)^2 ].
6. Using the resistance, capacitance, inductance, and the frequency of the AC Voltage calculate the impedance Z.
7. Place a Cu
ent Chart after the battery in the circuit. Note the maximum value of the cu
ent. Using the RMS cu
ent show that the RMS voltage from the AC Voltage is consistent with the RMS cu
ent and impedance.
8. Change the frequency of the AC Voltage to the resonant frequency and click Reset Dynamics. Allow the simulation to run for at least one minute to adjust. Repeat steps #4-7. What similarities and differences do you see between the two tests.
9. Screen grab your circuit and include the picture in your lab report. Save the circuit for your own records.
Answered Same Day Apr 22, 2021

Solution

Kamal answered on Apr 22 2021
158 Votes
Dice.cpp
Dice.cpp
  Dice.cpp
#include #include #include #include "Dice.h"
using namespace std;
void diceInit ()
{
    
 seed the random number generator with the time
    
  -> you don't have to understand this line
    srand((unsigned int)time(NULL));
}
int diceRoll ()
{
    return rand() % DICE_SIDE_COUNT;
}
void dicePrint2and2 (int r1, int r2, int c1, int c2)
{
    cout 
 "    Row           Column" 
 endl;
    cout 
 "+---+ +---+     +---+ +---+" 
 endl;
    cout 
 "| " 
 r1 
 " | | " 
 r2 
 " |     "
         
 "| " 
 c1 
 " | | " 
 c2 
 " |" 
 endl;
    cout 
 "+---+ +---+     +---+ +---+" 
 endl;
}
void dicePrint2and2and1 (int r1, int r2, int c1, int c2, int e1)
{
    cout 
 "    Row           Column        Extra" 
 endl;
    cout 
 "+---+ +---+     +---+ +---+     +---+" 
 endl;
    cout 
 "| " 
 r1 
 " | | " 
 r2 
 " |     "
         
 "| " 
 c1 
 " | | " 
 c2 
 " |     "
         
 "| " 
 e1 
 " |" 
 endl;
    cout 
 "+---+ +---+     +---+ +---+     +---+" 
 endl;
}
Dice.h
Dice.h
A module to handle dice rolling.
#pragma once
const int DICE_SIDE_COUNT = 4;
void diceInit ();
int diceRoll ();
void dicePrint2and2 (int r1, int r2, int c1, int c2);
void dicePrint2and2and1 (int r1, int r2, int c1, int c2, int e1);
Game.cpp
Game.cpp
  Game.cpp
#include #include #include #include "Player.h"
#include "BoardSize.h"
#include "CellId.h"
#include "Tile.h"
#include "Board.h"
#include "AvailableTiles.h"
#include "Dice.h"
#include "CellChooser.h"
#include "Game.h"
using namespace std;
Game :: Game ()
    : board(),
      available()
{
}
void Game :: printState (unsigned int whose_turn) const
{
    assert(whose_turn < playerGetCount());
    board.print();
    cout 
 endl;
    available.print();
    cout 
 endl;
    cout 
 playerGetName(whose_turn) 
 "'s turn:" 
 endl;
    cout 
 endl;
}
void Game :: handleDiceRoll (unsigned int whose_turn)
{
    assert(whose_turn < playerGetCount());
    bool is_extra_die = false;
    if(playerHasDice(whose_turn, 1))
    {
        is_extra_die = true;
        playerDecreaseDice(whose_turn, 1);
    }
    int row1    = diceRoll();
    int row2    = diceRoll();
    int column1 = diceRoll();
    int column2 = diceRoll();
    int extra   = diceRoll();
    if(is_extra_die)
        dicePrint2and2and1(row1, row2, column1, column2, extra);
    else
        dicePrint2and2(row1, row2, column1, column2);
    cout 
 endl;  
 blank line
    
 ask player to choose a cell if needed
    CellChooser cell_chooser(row1, row2, column1, column2, extra, is_extra_die);
    if(!cell_chooser.isChosen())
    {
        cell_chooser.printAvailable();
        while(!cell_chooser.isChosen())
        {
            cout 
 "Choose a cell to roll: ";
            string input;
            getline(cin, input);
            if(isOnBoard(input))
            {
                CellId chosen = toCellId(input);
                if(cell_chooser.isAvailable(chosen))
                    cell_chooser.chooseAvailable(chosen);
                else
                    cout 
 "  Cell " 
 chosen 
 " is not available" 
 endl;
            }
            else
                cout 
 "  Invalid cell" 
 endl;
        }
    }
    else
        cout 
 "Rolled cell: " 
 cell_chooser.getChosen() 
 endl;
    CellId chosen_cell = cell_chooser.getChosen();
    assert(isOnBoard(chosen_cell));
    Tile tile = board.getAt(chosen_cell);
    tile.activate(whose_turn);
}
ool Game :: puchaseTile (unsigned int whose_turn)
{
    assert(whose_turn < playerGetCount());
    playerPrint(whose_turn);
    string input;
    cout 
 "Choose a cell to place a tile: ";
    getline(cin, input);
    if(input == "q")
        return true;  
 player wants to quit
    bool is_discard_tile = true;
    if(isOnBoard(input))
    {
        CellId chosen_cell = toCellId(input);
        assert(isOnBoard(chosen_cell));
        if(!board.getAt(chosen_cell).isOwner())
        {
            int tile_index;
            cout 
 "Choose a tile to buy (by index): ";
            cin 
 tile_index;
            cin.clear();  
 clean up bad input
            getline(cin, input);  
 read to end of line
                
            if(tile_index >= 0 && tile_index < AVAILABLE_TILE_COUNT)
            {
                int cost = available.getCost(tile_index);
                if(playerHasMoney(whose_turn, cost))
                {
                    board.setAt(chosen_cell, available.getTile(tile_index), whose_turn);
                    playerDecreaseMoney(whose_turn, cost);
                    available.replaceAt(tile_index);
                    is_discard_tile = false;
                    cout 
 "Success: Tile added" 
 endl;
                }
                else
                    cout 
 "Failure: Not enough money" 
 endl;
            }
            else
                cout 
 "Failure: Invalid tile" 
 endl;
        }
        else
            cout 
 "Failure: Cell already has an owner" 
 endl;
    }
    else
        cout 
 "Failure: Invalid cell" 
 endl;
    if(is_discard_tile)
        available.replaceAt(0);
    return false;  
 player does not want to quit
}
Game.h
Game.h
A module to represent the complete state of the game.
#pragma once
#include #include "BoardSize.h"
#include "CellId.h"
#include "Tile.h"
#include "Board.h"
#include "AvailableTiles.h"
Game
A class to represent the complete state of the game.
class Game
{
public:
    Game ();
    void printState (unsigned int whose_turn) const;
    void handleDiceRoll (unsigned int whose_turn);
    bool puchaseTile (unsigned int whose_turn);
private:
    Board board;
    AvailableTiles available;
};
Main.cpp
Main.cpp
  Main.cpp
  The main program for Assignment 5.
  For Dr. Hamilton's CS 115 class, 202110 (Winter) term.
  Name: ___________________
  Student number: _________
#include #include #include #include "Dice.h"
#include "Player.h"
#include "Game.h"
using namespace std;
const int POINTS_TO_WIN = 5;
int main ()
{
    
 setup
    diceInit();
    string player_names[2] = { "Alice", "Bob" };
    playerInit(2, player_names);
    Game game;
    cout 
 "Welcome to the game." 
 endl;
    
 run main loop
    unsigned int cu
ent_player = 0;
    bool is_quit = false;
    
    do
    {
        cout 
 endl;
        cout 
 endl;
        assert(cu
ent_player < playerGetCount());
        game.printState(cu
ent_player);
        game.handleDiceRoll(cu
ent_player);
        cout 
 endl;
        is_quit = game.puchaseTile(cu
ent_player);
        cu
ent_player++;
        if(cu
ent_player >= playerGetCount())
            cu
ent_player = 0;
    }
    while (!is_quit && !playerHasPointsAnyone(POINTS_TO_WIN));
    
 print end messages
    cout 
 endl;
    cout 
 endl;
    for(unsigned int p = 0; p < playerGetCount(); p++)
    {
        playerPrint(p);
    }
    cout 
 endl;
    cout 
 "Thank you for playing!" 
 endl;
    return 0;  
 program exited without crashing
}
Player.cpp
Player.cpp
  Player.cpp
#include #include #include #include #include "Player.h"
using namespace std;
const unsigned int START_MONEY  = 0;
const unsigned int START_DICE   = 1;
const unsigned int START_POINTS = 0;
struct Playe
{
    string name;
    int money;
    int dice;
    int points;
};
static Player players[PLAYER_COUNT_MAX];
static unsigned int player_count = 0;
static bool isInvariantTrue ()
{
    if(player_count > PLAYER_COUNT_MAX)
        return false;
    for(unsigned int i = 0; i < player_count; i++)
        if(players[i].name == "")
            return false;
    return true;
}
void playerInit (unsigned int player_count1,
                 const string names[])
{
    assert(isInvariantTrue());
    assert(player_count1 >= PLAYER_COUNT_MIN);
    assert(player_count1 <= PLAYER_COUNT_MAX);
    for(unsigned int i = 0; i < player_count1; i++)
        assert(names[i] != "");
    player_count = player_count1;
    for(unsigned int i = 0; i < player_count; i++)
    {
        players[i].name = names[i];
        players[i].money  = START_MONEY;
        players[i].dice   = START_DICE;
        players[i].points = START_POINTS;
    }
    assert(isInvariantTrue());
}
unsigned int isInitialized ()
{
    assert(isInvariantTrue());
    if(player_count >= PLAYER_COUNT_MIN &&
       player_count <= PLAYER_COUNT_MAX)
    {
        return true;
    }
    else
        return false;
}
unsigned int playerGetCount ()
{
    assert(isInvariantTrue());
    assert(isInitialized());
    return player_count;
}
unsigned int playerGetIndex (const string& name)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(name != "");
    for(unsigned int i = 0; i < player_count; i++)
    {
        if(players[i].name == name)
            return i;
    }
    
 if we get here, there was no player with name name
    return NO_SUCH_PLAYER;
}
void playerPrint (unsigned int player_index)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    cout        
 setw(8) 
 left 
 players[player_index].name
         
 "$" 
 setw(4) 
 left 
 players[player_index].money
         
 "#" 
 setw(4) 
 left 
 players[player_index].dice
         
 "*" 
 setw(4) 
 left 
 players[player_index].points 
 endl;
}
const string& playerGetName (unsigned int player_index)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    return players[player_index].name;
}
char playerGetTileChar (unsigned int player_index)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(players[player_index].name.size() > 0);
    return players[player_index].name[0];
}
ool playerHasMoney (unsigned int player_index,
                     int money)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(money >= 0);
    if(players[player_index].money >= money)
        return true;
    else
        return false;
}
ool playerHasDice (unsigned int player_index,
                    int dice)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(dice >= 0);
    if(players[player_index].dice >= dice)
        return true;
    else
        return false;
}
ool playerHasPointsAnyone (int points)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(points >= 0);
    for(unsigned int i = 0; i < player_count; i++)
    {
        if(players[i].points >= points)
            return true;
    }
    return false;
}
void playerIncreaseMoneyAndPrint (unsigned int player_index,
                                  int increase)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(increase >= 0);
    int old_money = players[player_index].money;
    players[player_index].money += increase;
    int new_money = players[player_index].money;
    cout 
 players[player_index].name 
 "'s money:"
         
   " $" 
 old_money
         
 " + $" 
 increase
         
 " = $" 
 new_money 
 endl;
    assert(isInvariantTrue());
}
void playerIncreaseDiceAndPrint (unsigned int player_index,
                                 int increase)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(increase >= 0);
    int old_dice = players[player_index].dice;
    players[player_index].dice += increase;
    int new_dice = players[player_index].dice;
    cout 
 players[player_index].name 
 "'s dice:"
         
   " #" 
 old_dice
         
 " + #" 
 increase
         
 " = #" 
 new_dice 
 endl;
    assert(isInvariantTrue());
}
void playerIncreasePointsAndPrint (unsigned int player_index,
                                   int increase)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(increase >= 0);
    int old_points = players[player_index].points;
    players[player_index].points += increase;
    int new_points = players[player_index].points;
    cout 
 players[player_index].name 
 "'s points:"
         
   " *" 
 old_points
         
 " + *" 
 increase
         
 " = *" 
 new_points 
 endl;
    assert(isInvariantTrue());
}
void playerDecreaseMoney (unsigned int player_index,
                          int decrease)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(decrease >= 0);
    assert(playerHasMoney(player_index, decrease));
    assert(players[player_index].money >= decrease);
    players[player_index].money -= decrease;
    assert(isInvariantTrue());
}
void playerDecreaseDice (unsigned int player_index,
                         int decrease)
{
    assert(isInvariantTrue());
    assert(isInitialized());
    assert(player_index < playerGetCount());
    assert(decrease >= 0);
    assert(playerHasDice(player_index, decrease));
    assert(players[player_index].dice >= decrease);
    players[player_index].dice -= decrease;
    assert(isInvariantTrue());
}
Player.h
Player.h
A module to keep track of the information for the players.
Each player has a name and an amount of money, dice, and
points. The amount of money and the number of dice can be
increased and decreased, while the number of points can
only be increased.
This is an encapsulated global service.
#pragma once
#include PLAYER_COUNT_MIN
The minimum number of players in the game.
const unsigned int PLAYER_COUNT_MIN = 1;
PLAYER_COUNT_MAX
The maximum number of players in the game.
const unsigned int PLAYER_COUNT_MAX = 4;
NO_SUCH_PLAYER
A special value indicating that there was not a player with
the requested name.
const unsigned int NO_SUCH_PLAYER = 999999;
playerInit
Purpose: To initialize the Player module for the specified
players. Each player starts with $0 money, #1 die,
and *0 points.
Parameter(s):
<1> count: The number of players in the game
<2> names: The player names
Precondition(s):
<1> count >= PLAYER_COUNT_MIN
<2> count < PLAYER_COUNT_MAX
<3> names[i] != "" WHERE 0 <= i < count
Returns: N/A
Side Effect: The players module is initialized to contain
count players with the first count names in
names. If the module was already initialized,
all infromation about the previous players is
lost.
void playerInit (unsigned int count,
const std::string names[]);
isInitialized
Purpose: To determine whether the player module has been
initialized.
Parameter(s): N/A
Precondition(s): N/A
Returns: Whether the player module is initialized.
Side Effect: N/A
unsigned int isInitialized ();
playerGetCount
Purpose: To determine the number of players in the game.
Parameter(s): N/A
Precondition(s):
<1> isInitialized()
Returns: How many players in the game.
Side Effect: N/A
unsigned int playerGetCount ();
playerGetIndex
Purpose: To determine the index of the player with the
specified name.
Parameter(s):
<1> name: The player name
Precondition(s):
<1> isInitialized()
<2> name != ""
Returns: The index of the player with name name. If there
isn't a player with that name, NO_SUCH_PLAYER is
returned.
Side Effect: N/A
unsigned int playerGetIndex (const std::string& name);
playerPrint
Purpose: To print the information for the specified player.
Parameter(s):
<1> player_index: Which playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
Returns: N/A
Side Effect: The name, money, dice, and points for playe
player_index is printed to standard output
(cout).
void playerPrint (unsigned int player_index);
playerGetName
Purpose: To determine the specified player's name.
Parameter(s):
<1> player_index: Which playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
Returns: The name of player player_index.
Side Effect: N/A
const std::string& playerGetName (unsigned int who);
playerGetTileCha
Purpose: To determine the character that the specified
player uses to mark tile ownership.
Parameter(s):
<1> player_index: Which playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
Returns: The char used to show that player player_index owns
a tile.
Side Effect: N/A
char playerGetTileChar (unsigned int player_index);
playerHasMoney
Purpose: To determine if the specified player has at least
the specified amount of money.
Parameter(s):
<1> player_index: Which playe
<2> money: How much money to check fo
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> money >= 0
Returns: Whether player player_index has at least money
money.
Side Effect: N/A
ool playerHasMoney (unsigned int player_index,
int money);
playerHasDice
Purpose: To determine if the specified player has at least
the specified number of dice.
Parameter(s):
<1> player_index: Which playe
<2> dice: How many dice to check fo
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> dice >= 0
Returns: Whether player player_index has at least dice dice.
Side Effect: N/A
ool playerHasDice (unsigned int player_index,
int dice);
playerHasPointsAny
Purpose: To determine if any player has at least the
specified number of points.
Parameter(s):
<1> points: How many points to check fo
Precondition(s):
<1> isInitialized()
<2> points >= 0
Returns: Whether any player has at least points points.
Side Effect: N/A
ool playerHasPointsAnyone (int points);
playerIncreaseMoneyAndPrint
Purpose: To give the specified player the specified amount
of additional money.
Parameter(s):
<1> player_index: Which playe
<2> increase: How much money to give the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> increase >= 0
Returns: N/A
Side Effect: Player player_index gains increase money. The
change to the player's money is printed,
including the player name.
void playerIncreaseMoneyAndPrint (unsigned int player_index,
int increase);
playerIncreaseDiceAndPrint
Purpose: To give the specified player the specified numbe
of additional dice.
Parameter(s):
<1> player_index: Which playe
<2> increase: How many dice to give the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> increase >= 0
Returns: N/A
Side Effect: Player player_index gains increase dice. The
change to the player's number of dice is
printed, including the player name.
void playerIncreaseDiceAndPrint (unsigned int player_index,
int increase);
playerIncreasePointsAndPrint
Purpose: To give the specified player the specified numbe
of additional points.
Parameter(s):
<1> player_index: Which playe
<2> increase: How many points to give the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> increase >= 0
Returns: N/A
Side Effect: Player player_index gains increase points. The
change to the player's points is printed,
including the player name.
void playerIncreasePointsAndPrint (unsigned int player_index,
int increase);
playerDecreaseMoney
Purpose: To reduce the specified player's money by the
specified amount.
Parameter(s):
<1> player_index: Which playe
<2> decrease: How much money to take from the playe
Precondition(s):
<1> isInitialized()
<2> player_index < playerGetCount()
<3> decrease >= 0
<4> playerHasdDice(player_index, decrease)
Returns: N/A
Side Effect: Player player_index...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here