CS 52 Assignment 5
Project 2 - Record Player
write C++
Following the class diagram shown below, create the class RecordPlayer. An RecordPlayerrepresents a stereo component that can play vinyl records. Please review the class and the sample driver code. There is a specific order to the way the class methods should be called. In other words, you can’t plop the Needle unless there actually is a record on the player and the recordplayeris turned on. You also can’t return the Needle unless there is actually a record on the player and the recordplayeris turned on. Your class should enforce these rules and write errors to cout as they occur. A sample driver for this class is shown below.
Rules of the record player
Please note: codeboard must test differently for this project. There is no input. The provided driver will be called automatically. Your code will not compile when you start the project; only when you’ve implemented the RecordPlayer class will it compile successfully.
Record Player
RecordPlayer( ); void turnOn( ); void turnOff( ); bool isPoweredOn( ); void affixPlatter( string record ); void plopNeedle( ); void returnNeedle( ); bool isOn; string record; bool needleIsOnTheRecord;
Record Player Sample Driver Code
//declare 6 RecordPlayers RecordPlayer good_r, bad_r1, bad_r2, bad_r3, bad_r4, bad_r5; //first test correct good_r.turnOn(); good_r.affixPlatter("Barrow Manila I"); good_r.plopNeedle(); good_r.returnNeedle(); good_r.turnOff(); //bad test, plops needle without turning it on or putting record on bad_r1.plopNeedle(); //turns it on but no record on platter bad_r2.turnOn(); bad_r2.plopNeedle(); //not on nor has album on platter bad_r3.returnNeedle(); //turned on but no album bad_r4.turnOn(); bad_r4.returnNeedle(); //not turned on bad_r5.affixPlatter("Barrow Manila I"); bad_r5.plopNeedle();
Record Player Sample Driver Code Output
Record player is turned on Record Barrow Manila I is now on the platter Needle is placed on the record Needle is returned from the record Record player is turned off Cannot place needle on the record Record player is turned on Cannot place needle on the record Cannot return needle from the record Record player is turned on Cannot return needle from the record Record Barrow Manila I is now on the platter Cannot place needle on the record
Working code implemented in C++ and appropriate comments provided for better understanding:
Here I am attaching code for these 3 files:
Source code for main.cpp:
// include necessary files
#include <iostream>
#include "record_player.h"
using namespace std;
int main()
{
// declare 6 RecordPlayers
RecordPlayer good_r, bad_r1, bad_r2, bad_r3, bad_r4, bad_r5;
// first test correct
good_r.turnOn();
good_r.affixPlatter("Barrow Manila I");
good_r.plopNeedle();
good_r.returnNeedle();
good_r.turnOff();
// bad test, plops needle without turning it on or putting
record on
bad_r1.plopNeedle();
// turns it on but no record on platter
bad_r2.turnOn();
bad_r2.plopNeedle();
// not on nor has album on platter
bad_r3.returnNeedle();
// turned on but no album
bad_r4.turnOn();
bad_r4.returnNeedle();
// not turned on
bad_r5.affixPlatter("Barrow Manila I");
bad_r5.plopNeedle();
// exit cleanly
return 0;
}
Code Screenshots:
Source code for record_player.cpp:
#include "record_player.h"
RecordPlayer::RecordPlayer()
{
record = "";
isOn = false;
needleIsOnTheRecord = false;
}
void RecordPlayer::turnOn()
{
isOn = true;
cout << "Record player is turned on" << endl;
}
void RecordPlayer::turnOff()
{
isOn = false;
cout << "Record player is turned off" << endl;
}
bool RecordPlayer::isPoweredOn()
{
return isOn;
cout << "Record player is powered on" << endl;
}
void RecordPlayer::affixPlatter(string r)
{
record = r;
cout << "Record " << record << " is now on the
platter" << endl;
}
void RecordPlayer::plopNeedle()
{
if (record != "" && isOn)
{
needleIsOnTheRecord = true;
cout << "Needle is placed on the record" << endl;
}
else
{
cout << "Cannot place needle on the record" <<
endl;
}
}
void RecordPlayer::returnNeedle()
{
if (record != "" && isOn)
{
needleIsOnTheRecord = false;
cout << "Needle is returned from the record" <<
endl;
}
else
{
cout << "Cannot return needle from the record" <<
endl;
}
}
Code Screenshots:
Source code for record_player.h:
#include <iostream>
#include <string>
using namespace std;
class RecordPlayer
{
public:
RecordPlayer();
void turnOn();
void turnOff();
bool isPoweredOn();
void affixPlatter(string r);
void plopNeedle();
void returnNeedle();
private:
bool isOn;
string record;
bool needleIsOnTheRecord;
};
Code Screenshots:
Output Screenshots:
Hope it helps, if you like the answer give it a thumbs up. Thank you.
CS 52 Assignment 5 Project 2 - Record Player write C++ Following the class diagram shown...
Project 1 - Wallet Following the class diagram shown below, create the class Wallet. A Wallet represents a carrier of bills and coins. You use your wallet to pay for things, which reduces the balance held inside. When you visit an ATM, you can fill it back up with cash again. A sample driver for this class is shown below. You should probably make a more thorough driver to test your class better. I will have my own driver which...
Project 2 - Flashdrive 1.0 I have provided you with a sample class named FlashDrive which has been diagrammed below and described in the online course content. For this unit, I'd like you to identify additional member variables (data) that would be appropriate for the class FlashDrive. I would also like you to identify additional methods (functions) that would be appropriate for the class FlashDrive. Submit a .h file for FlashDrive with the new possible methods and members you have...
I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding of how to implement copy constructors, destructors, and assignment operators is essential when working with data structures using dynamic memory allocation. Failure to implement these methods correctly can and probably will result in memory leaks. In this project, you are provided with a working implementation of a doubly-linked list in which the copy constructor, destructor, and assignment operator methods are not complete. To complete...
Help please with a Project in C++ In C++, many of the keyboard symbols that are used between two variables can be given a new meaning. This feature is called operator overloading and it is one of the most popular C++ features. Any class can choose to provide a new meaning to a keyboard symbol. Not every keyboard letter is re-definable in this way, but many of the ones we have encountered so far are like +, -, *, /,...
Project 1 - Operator Overloading (FlashDrive 2.0) In C++, many of the keyboard symbols that are used between two variables can be given a new meaning. This feature is called operator overloading and it is one of the most popular C++ features. Any class can choose to provide a new meaning to a keyboard symbol. Not every keyboard letter is re-definable in this way, but many of the ones we have encountered so far are like +, -, *, /,...
Please help ASAP! C ++, linked list, etc. everything for the project is in the link below. https://www.zipshare.com/download/eyJhcmNoaXZlSWQiOiIzZDIyN2UzYi1kNGFhLTRlMzEtYjMzZi00MDhmYzNiMjk3ZGMiLCJlbWFpbCI6Im1pMTQzNEBnbWFpbC5jb20ifQ== You should turn it in by blackboard. Each task should be in a separate unzipped folder named YourLastName_YourFirstInitial_taskN, where N is the task number inside a zipped file named: YourLastName_YourFirstInitial.zip. You may use code you have written previously and you may ask other members of the class questions about the assignment. However, you must do your own assignment; you may not use...
In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member called gameState that holds one of the following values: X_WON, O_WON, or UNFINISHED - use an enum type for this, not string (the...
Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...
I need help finding the error in my code for my Fill in the Blank (Making a Player Class) in C++. Everything looks good to me but it will not run. Please help... due in 24 hr. Problem As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. Currently, there is a test...
This needs to be done in c++11 and be compatible with g++ compiling Project description: Write a C++ program to simulate a simple card game between two players. The game proceeds as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. Remaining cards are placed in a pile face-down between the two players. Players then select a card from the three in their hand. The player...