I need C++ code
Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required:
NOTE: Your linked list class should NOT be templated.
Example: If the input is:
3 Linda Ronstadt You're no good 2.30 Rock Elton John Rocket Man 4.41 Rock Antonin Leopold Dvorak Songs my mother taught me 2.24 Classical
where 3 is the number of songs, and each subsequent four lines is an (artist, title, length, genre) record, the output is:
Antonin Leopold Dvorak, Songs my mother taught me, 2.24, Classical Elton John, Rocket Man, 4.41, Rock Linda Ronstadt, You're no good, 2.3, Rock
Edit main to demonstrate all implemented functions!
_______________________________________________
#include <iostream>
#include <string>
#include "playlist.h"
using namespace std;
int main()
{
song tune;
string genre;
playlist mySongs;
int num = 0;
cin >> num >> ws;
for (int i=0; i<num; i++)
{
getline(cin, tune.artist);
getline(cin, tune.title);
cin >> tune.length >> ws;
getline(cin, genre);
if (genre == "Rock")
tune.genre = genre_t::ROCK;
else if (genre == "Country")
tune.genre = genre_t::COUNTRY;
else if (genre == "Pop")
tune.genre = genre_t::POP;
else if (genre == "Classical")
tune.genre = genre_t::CLASSICAL;
else
tune.genre = genre_t::POLKA;
mySongs.addSong(tune);
}
mySongs.displayList();
return 0;
}
________________________________________________
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <iostream>
#include <string>
enum class genre_t {ROCK, COUNTRY, POP, CLASSICAL, POLKA};
struct song
{
std::string artist;
std::string title;
float length;
genre_t genre;
song* next;
};
class playlist
{
public:
// TODO: add the required member functions and operator
private:
song* head;
};
#endif
_________________________________________________________________
#include "playlist.h"
// TODO: implement the class member functions and overloaded operator
In: Computer Science
Write a general-purpose program with loop and indexed addressing
that adds 12h to 0th, 3rd , 7th , 11th ,15th ,19th , ... elements
of a DWORD array. For example, in array:
Array1 DWORD 12h, 13h, 14h,15h, 16h, 17h, 18h, 19h, 1ah, 1bh, 1ch,
1dh, 1eh, 1fh becomes:
Array1 : 24h, 13h, 14h, 27h,16h,17h,18h, 2bh, 1ah, 1bh, 1ch, 2f,
1eh, 1fh
In: Computer Science
Exercise 1: Write a C program that does the following tasks:
a. Declare a structure called StudRec with four components:
an int containing the StuId,
a string containing the StudName,
a string containing the MajorName,
b. Define typedef List to be a synonym for the type struct StudRec.
c. Declare a global variable array StudST[] of List.
d. Declare a global variable Ptr to be a pointer to List.
e. Write a C function (return pointer to List) that does the following. It accepts the StudST array and an N integer denoting the actual size of the array, read and fill N student details using structure, Dynamic Memory Allocation from the keyboard and return a pointer of List.
f. Declare a structure called Major with two components:
a string containing the MajorName,
an int NumSt containing the number of students in the Major,
g. Declare a global variable array MajorST[] of structure Major.
h. Write a C function that does the following. It accepts the MajorST array with 4 integer denoting the actual size of the array and update the array with 4 MajorName read from the keyboard and assign 0 to NumSt.
i. Write a C function that does the following. It accepts, as arguments, the StudST array (e) with N integer denoting the actual size of the array and the MajorST array (h). Using StudST, the function calculates the number of students in each major and updates the MajorST array by these numbers for each MajorName.
j. Compile and Run the previous statements in a main C file.
In: Computer Science
I need to develop an abstract class/ class that will be called RandString will be used as a base class for two derived classes: RandStr will generate a random string with 256 characters long and a RandMsgOfTheDay will return a random message the day. (use a table of message in memory - or in a file).
In: Computer Science
How to sort with bubble sort/merge sort with linked lists, only swapping the data not the nodes (in python)
In: Computer Science
I AM USING R PROGRAMMING LANGUAGE / R- CODE
**Problem 3 (5 pts) - similar to Pr. 44 page 243 in text** Consider tossing **four** fair coins. There are 16 possible outcomes, e.g `HHHH,HHHT,HHTH,HTHH,THHH, ...` possible outcomes. Define `X` as the random variable “number of heads showing when four coins are tossed.” Obtain the mean and the variance of X. Simulate tossing three fair coins 10,000 times. Compute the simulated mean and variance of X. Are the simulated values within 2% of the theoretical answers?
Hint: to find the theoretical values use `dbinom (x= , size = , prob = )`
**Solution:**YOUR CODE HERE:
```{r}
```
In: Computer Science
Using PYTHON. Implement the stooge sort algorithm3to sort an array/vector of integers.
Your program should be able to read inputs from a file called “data.txt” where the first value of each line is the number of integers that need to be sorted, followed by the integers
The output will be written to a file called “stooge.txt”.
Stooge sort is a “bad” recursive sorting algorithm. Given an array A, the algorithm can be defined as follows:
Step 1:
If the value at the leftmost position of the array is larger than the value at the rightmost position then swap values.
Step 2: If there are 3 or more elements in the array, then:
Recursively call Stooge sort with the initial 2/3 of the array
Recursively call Stooge sort with the last 2/3 of the array.
Recursively call Stooge sort with the initial 2/3 of the array again.
Examplevalues for data.txt :
4 19 2 5 11
8 1 2 3 4 5 6 1 2
In: Computer Science
Linux Create two subprocesses using the system call fork(), and then use the system call signal() to let the parent process capture the interrupt signal on the keyboard (i.e., press the DEL key); The subprocess terminates after the subprocess captures the signal and outputs the following information separately: “Child Process l is Killed by Parent!” “Child Process 2 is Killed by Parent!” After the two child processes terminate, the parent process output the following information and terminate itself: “Parent Process is Killed!” Program with screen shot and explanation. Thank you
In: Computer Science
Apex Computing is preparing for a Secret Santa gift exchange. Certain information will be gathered from each employee. Although it would be more realistic to write a program that asks a user for input, this program will just be a practice for using structures and functions so we will create the information by assigning values to the variables.
Write a program that uses a structure named EmpInfo to store the following about each employee:
Name
Age
Favorite Food
Favorite Color
The program should create three EmpInfo variables, store values in their members, and pass each one, in turn, to a function that displays the information in a clear and easy-to-read format. (Remember that you will choose the information for the variables.)
Here is an example of the output:
Name………………………………Mary Smith
Age ……………………………….. 25
Favorite food ………………… Pizza
Favorite color ……………….. Green
In: Computer Science
NEED TO BE IN PYTHON!!!
Make sure to put the main section of your code in the following if
block:
# Type code for classes here
if __name__ == "__main__":
# Type main section of code here
(1) Build the Account class with the following specifications:
Attributes
Create a constructor that has 3 parameters (in addition to self) that will be passed in from the user. (no default values)
Define a __str__() method to print an Account like the following
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $100.00
Define a deposit() method that has 1 parameter (in addition to self) that will be passed in from the user. (no default values) The method deposits the specified amount in the account.
Define a withdraw() method that has 2 parameters (in addition to self) that will be passed in from the user. (no default values) The method withdraws the specified amount (1st parameter) and fee (2nd parameter) from the account.
(2) In the main section of your code, create 3 accounts.
(3) Print the 3 accounts using print(acct1)…
(4) Deposit 25.85, 75.50 and 50 into accounts 1, 2 and 3.
(5) Print the 3 accounts.
(6) Withdraw 25.85 (2.50 fee), 75.50 (1.50 fee), 50.00 (2.00 fee).
(7) Print the 3 accounts.
Output should look like the following:
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $100.00
Account Name: Donald Duck
Account Number: 83504837
Account Balance: $100.00
Account Name: Joe Smith
Account Number: 74773321
Account Balance: $100.00
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $125.85
Account Name: Donald Duck
Account Number: 83504837
Account Balance: $175.50
Account Name: Joe Smith
Account Number: 74773321
Account Balance: $150.00
Account Name: Trish Duce
Account Number: 90453889
Account Balance: $97.50
Account Name: Donald Duck
Account Number: 83504837
Account Balance: $98.50
Account Name: Joe Smith
Account Number: 74773321
Account Balance: $98.00
In: Computer Science
You will use the definition of the linked-queue from lab6, and re-write it as a template for a linked-queue (I hope you finished the function definitions)
In the driver file, create and use queues of different types to show it works.
In the documentation, indicate if there are any types it won’t work for, and why not.
driver.cpp
#include <iostream>
using namespace std;
#include "LQueue.h"
void print(Queue q)
{
q.display(cout);
}
int main()
{
Queue q1;
cout << "Queue created. Empty? " << boolalpha <<
q1.empty() << endl;
cout << "How many elements to add to the queue? ";
int numItems;
cin >> numItems;
for (int i = 1; i <= numItems; i++)
q1.enqueue(100 * i);
cout << "Contents of queue q1 (via print):\n";
print(q1); cout << endl;
Queue q2;
q2 = q1;
cout << "Contents of queue q2 after q2 = q1 (via
print):\n";
print(q2); cout << endl;
cout << "Queue q2 empty? " << q2.empty() <<
endl;
cout << "Front value in q2: " << q2.front() <<
endl;
while (!q2.empty())
{
cout << "Remove front -- Queue contents: ";
q2.dequeue();
q2.display(cout);
}
cout << "Queue q2 empty? " << q2.empty() <<
endl;
cout << "Front value in q2?" << endl <<
q2.front() << endl;
cout << "Trying to remove front of q2: " << endl;
q2.dequeue();
return 0;
}
LQueue.h
#include <iostream>
#ifndef LQUEUE
#define LQUEUE
typedef int QueueElement;
class Queue
{
public:
/***** Function Members *****/
/***** Constructors *****/
Queue();
/*-----------------------------------------------------------------------
Construct a Queue object.
Precondition: None.
Postcondition: An empty Queue
object has been constructed.
(myFront and myBack are initialized to null pointers).
-----------------------------------------------------------------------*/
Queue(const Queue & original);
/*-----------------------------------------------------------------------
Copy Constructor
Precondition: original is the queue
to be copied and is received
as a
const reference parameter.
Postcondition: A
copy of original has been constructed.
-----------------------------------------------------------------------*/
/***** Destructor *****/
~Queue();
/*-----------------------------------------------------------------------
Class destructor
Precondition: None.
Postcondition: The linked list
in the queue has been deallocated.
-----------------------------------------------------------------------*/
/***** Assignment *****/
const Queue & operator= (const Queue &
rightHandSide);
/*-----------------------------------------------------------------------
Assignment Operator
Precondition: rightHandSide is the
queue to be assigned and is
received as a const reference parameter.
Postcondition: The
current queue becomes a copy of rightHandSide
and a reference to it is returned.
-----------------------------------------------------------------------*/
bool empty() const;
/*-----------------------------------------------------------------------
Check if queue is empty.
Precondition: None.
Postcondition: Returns true if
queue is empty and false otherwise.
-----------------------------------------------------------------------*/
void enqueue(const QueueElement & value);
/*-----------------------------------------------------------------------
Add a value to a queue.
Precondition: value is to be
added to this queue.
Postcondition: value is added at
back of
queue.
-----------------------------------------------------------------------*/
void display(ostream & out) const;
/*-----------------------------------------------------------------------
Display values stored in the queue.
Precondition: ostream out is
open.
Postcondition: Queue's contents,
from front to back, have been
output to out.
-----------------------------------------------------------------------*/
QueueElement front() const;
/*-----------------------------------------------------------------------
Retrieve/Peep value at front of queue (if
any).
Precondition: Queue is
nonempty.
Postcondition: Value at front of
queue is returned, unless the queue
is empty; in that case, an error
message is displayed and a
"garbage value" is
returned.
-----------------------------------------------------------------------*/
void dequeue();
/*-----------------------------------------------------------------------
Remove value at front of queue (if any).
Precondition: Queue is
nonempty.
Postcondition: Value at front of
queue has been removed, unless
queue is empty; in that case, an
error message is displayed
and execution allowed to
proceed.
-----------------------------------------------------------------------*/
private:
void delete_q(); // utility/helper function to delete queues
for
// destructor and assignment
operator
/*** Node class for the
queue***/
class Node
{
public:
QueueElement data;
Node * next;
//--- Node constructor
Node(QueueElement value, Node * link = 0)
/*-------------------------------------------------------------------
Precondition: value and link are received
Postcondition: A Node has been constructed with value in its
data part and its next part
set to link (default 0).
------------------------------------------------------------------*/
{
data = value; next = link;
}
}; //for Node class
typedef Node * NodePointer;
/***** Data Members *****/
NodePointer myFront, // pointer to
front of queue
myBack;
// pointer to back of queue
}; // end of class declaration
#endif
LQueue-Incomplete.cpp
#include <new>
using namespace std;
#include "LQueue.h"
//--- Definition of Queue constructor
Queue::Queue()
: myFront(0), myBack(0)
{}
//--- Definition of Queue copy constructor
Queue::Queue(const Queue & original)
{
myFront = myBack = 0;
if (!original.empty())
{
// Copy first node
myFront = myBack = new Node(original.front());
// Set pointer to run through original's linked
list
NodePointer origPtr = original.myFront->next;
while (origPtr != 0)
{
myBack->next = new
Node(origPtr->data);
myBack = myBack->next;
origPtr = origPtr->next;
} //while
} //if
}
void Queue::delete_q(void) {
// Set pointer to run through the queue
NodePointer prev = myFront, // node to be released/deleted
ptr; // points to the front node
while (prev != 0)
{
ptr = prev->next;
delete prev;
prev = ptr;
}
}
//--- Definition of Queue destructor
// delete queue from the front
Queue::~Queue()
{
delete_q();
}
//--- Definition of assignment operator
const Queue & Queue::operator=(const Queue &
rightHandSide)
{
if (this !=
&rightHandSide)
// check that not q = q
{
this->delete_q();
// destroy current linked list
if
(rightHandSide.empty()) //
empty queue
myFront = myBack = 0;
else
{
// copy rightHandSide's list
//
Copy first node
myFront = myBack = new
Node(rightHandSide.front());
// Set pointer to run through rightHandSide's
linked list
NodePointer rhsPtr =
rightHandSide.myFront->next;
while (rhsPtr != 0)
{
myBack->next = new
Node(rhsPtr->data);
myBack = myBack->next;
rhsPtr = rhsPtr->next;
}
}
}
return *this;
}
//--- Definition of empty()
bool Queue::empty() const
{
return (myFront == 0);
}
//--- Definition of enqueue()
void Queue::enqueue(const QueueElement & value)
{
NodePointer newptr = new Node(value);
if (empty())
myFront = myBack = newptr;
else
{
myBack->next = newptr;
myBack = newptr;
}
}
//--- Definition of display()
void Queue::display(ostream & out) const
{
NodePointer ptr;
for (ptr = myFront; ptr != 0; ptr = ptr->next)
out << ptr->data << " ";
out << endl;
}
//--- Definition of front()
// Peep the first element of the queue
QueueElement Queue::front() const
{
if (!empty())
return (myFront->data);
else
{
cerr << "*** Queue is empty "
" -- returning garbage ***\n";
QueueElement * temp = new(QueueElement);
QueueElement garbage = *temp;
// "Garbage" value
delete temp;
return garbage;
}
}
//--- Definition of dequeue()
// simply decrement the queue
void Queue::dequeue()
{
if (!empty())
{
NodePointer ptr = myFront;
myFront = myFront->next;
delete ptr;
if (myFront == 0) // queue is
now empty
myBack = 0;
}
else
cerr << "*** Queue is empty -- can't remove a
value ***\n";
}
In: Computer Science
Hello,
How can we create two buttons in a single page side by side through html?And how can we enter different data for different buttons, so that if i click 1st button it should show specific data and if i click second it should show other data?
In: Computer Science
write the program named Lab06.java that contains the following four static methods:
• public static double max(double[] data) that returns the maximum value in the array data
• public static double min(double[] data) that returns the minimum value in the array data
• public static double sum(double[] data) that sums all items in the array and return the result
• public static double ave(double[] data) that call the sum() method and then return the average.
Once you have completed the methods above, write a simple main program that does the following:
1. Asks the user how many items will be entered
2. Creates an array of double of the correct size
3. Prompts the user and reads in the values
4. Calculates and prints out the max, min, sum, and average using the methods above.
In: Computer Science
Im working on modifying my current code to function with these changes below
Create a Java program that meets the following criteria
My current code is show as below, i was wondering how i would go about doing that im a little lost.
import java.io.File;
import java.util.Scanner;
public class Lab5 {
public static void main(String[] args) {
String inFileName;
if (args.length > 1) {
inFileName = args[0];
} else {
Scanner console = new Scanner(System.in);
System.out.println("Enter a Filename: ");
inFileName = console.nextLine();
}
double[] myData = readArray(inFileName);
double[] results = processArray(myData);
// TODO: Display Results...
}
static double[] readArray(String filename) {
File inFile = new File(filename);
if (inFile.canRead()) {
try {
Scanner fileScanner = new Scanner(inFile);
int count = fileScanner.nextInt();
double[] data = new double[count];
for (int i = 0; i < count; i++) {
data[i] = fileScanner.nextDouble();
}
return data;
} catch (Exception e) {
return new double[0];
}
} else {
System.out.println("Can't read file.");
return new double[0];
}
}
static double[] processArray(double[] dataArray) {
// TODO: Implement Functionality from Requirements.
for (double data : dataArray) {
System.out.println(data);
}
return new double[0];
}
}In: Computer Science
Start with a program that allows the user to input a number of integers, and then stores them in an int array.
Write a function called maxint() that goes through the array, element by element, looking for the largest one.The function should take as arguments the address of the array and the number of elements in it, and return the index number of the largest element. The program should call this function and then display the largest element and its index number.
In: Computer Science