In this assignment, students shall create a single class in C++ that models a six-string guitar and the driver function to demonstrate the design's correctness. The class shall possess several methods relating to determining the pitch associated with a string and fret combination as well as a few private fields to hold information about the guitar's configuration.
A six string guitar uses six strings of different sizes to produce notes at different pitches. The guitar's fret-board is divided into several frets (typically 21). By plucking an "open" string, where one does not push a string against a fret, the guitar produces the note/pitch for that string's tuning. For example, plucking the open A string produces an A note with a pitch of 110 Hz. This is based on the frequency of the string's oscillation. If one pushes the string against the first fret, however, this effectively shortens the length of the string. Instead of oscillating from the guitar's bridge (the bottom) to the top of the neck, it can only oscillate from the bridge to the first fret position. This makes the string perform as if it were shorter, and, consequently, changes the acoustic pitch the guitar produces.
Thus, when pushing against the first fret on the A string, the guitar no longer produces an A note. Instead, it steps up one half tone and becomes Bb (B-flat). The pitch of an A string on a guitar is typically 110 Hz, and a Bb is higher pitched, so it oscillates faster at a rate of 116.5 Hz. Moving the finger on the string to the second fret on the A string produces a B with a pitch of 123.5 Hz.
The formula for determining the pitch based on a given fret is: Note x 2^(fret/12).
Thus, on an A with 110 Hz pitch, the note on the first fret is 110x2^(1/12) = 116.5 Hz. Were we on the D string at the fifth fret, the pitch would be 146.8 Hz x 2^(5/12) = 184.96 Hz.
By default, the guitar shall use "standard tuning": EADGBE
E: 82.41Hz
A: 110 Hz
D: 146.8 Hz
G: 196 Hz
B: 246.9 Hz
E: 329.6 Hz
The class must support changing the pitch of any of the six strings in the open position (no frets pushed). That is, this changes the guitar's tuning. In a typical use, a guitarist will change the tuning of the low E string such that it produces a D in the open position (drop-D tuning). Tom Morello did so for the Rage Against The Machine song Killing in the Name. This tuning change only impacts the specified string. All others retain their previous set tuning.
Notes in the scale:
A, Bb, B, C, C#, D, Eb, E, F, F#, G, Ab
Constructors:
// initializes the guitar to EADGBE tuning and a 21 fret guitar
default ()
// copy constructor (if the guitar allocates heap memory)
copy constructor (const Guitar&)
Destructor:
If your implementation of the Guitar class requests any heap memory, it shall include a destructor to free these locations when destroyed.
Public Fields:
The Guitar shall include no public fields.
Private Fields:
unsigned char numberOfFrets;
Methods:
// sets the corresponding private field and verifies the input is between 1 and 24
bool setFretBoardLength(const unsigned char numFrets);
// Returns the corresponding frequency in Hz for the given string and fret.
// Unlike array indices, these use natural numbers, so the low E string shall be
// string 1 and the high E string shall be 6
unsigned double pitchAt(const unsigned char &stringNumber, const unsigned char &fret);
// Given the pitch, the method shall return a std::pair object with the string/fret combination
// that comes closest to producing that pitch. There may be multiple solutions. The function
// shall return the first it identifies
std::pairgetStringAndFret( unsigned double pitch );
// changes the tuning for an individual string.
void tuneString(unsigned char& string, const double& pitch )