Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are trying to keep track of your CDs. Write a function makeCD(gn, ar, ti, yr

ID: 656485 • Letter: Y

Question

You are trying to keep track of your CDs.

Write a function makeCD(gn, ar, ti, yr, st, pr) that will create a structure with the following field name, Genre, Artist, Title, Year, Stars, Price

Use the following info:

Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with.

makeCD('Blues', 'Clapton, Eric', ...

'Sessions For Robert J', 2004, 2, 18.95 );

makeCD('Blues', 'Clapton, Eric', ...

'Sessions For Robert J', 2004, 2, 18.95 );

makeCD('Classical', ...

'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 );

makeCD( 'Country', 'Twain, Shania', ...

'Greatest Hits', 2004, 3.9, 13.49 );

makeCD( 'Latin', 'Trevi, Gloria', ...

'Como Nace El Universo', 2004, 5, 12.15 );

makeCD( 'Rock/Pop', 'Ludacris', ...

'The Red Light District', 2004, 4, 13.49 );

makeCD( 'R & B', '2Pac', ...

'Loyal To The Game', 2004, 3.9, 13.49 );

makeCD( 'Rap', 'Eminem', ...

'Encore', 2004, 3.5, 15.75 );

Explanation / Answer

#include<iostream>
#include<stdio.h>
#include<cstdlib>
#include<string.h>

using namespace std;
static int i=0; //make a global variable for counter

struct CD{   //define structure to hold CD data
    char genere[20];
    char artist[20];
    char title[20];
    int year;
    float stars;
    float price;
} c[10];

void makeCD(char *gn, char* ar, char* ti, int yr, float st, float pr){
    strcpy(c[i].genere,gn);
    strcpy(c[i].artist,ar);
    strcpy(c[i].title,ti);
    c[i].year=yr;
    c[i].stars=st;
    c[i].price=pr;
    i++;
}

int main(){
    makeCD("Blues", "Clapton, Eric", "Sessions For Robert J", 2004, 2, 18.95 );

    makeCD("Blues", "Clapton, Eric", "Sessions For Robert J", 2004, 2, 18.95 );

    makeCD("Classical","Bocelli, Andrea", "Andrea", 2004, 4.6, 14.89 );

    makeCD( "Country", "Twain, Shania", "Greatest Hits", 2004, 3.9, 13.49 );

    makeCD( "Latin", "Trevi, Gloria", "Como Nace El Universo", 2004, 5, 12.15 );

    makeCD( "Rock/Pop", "Ludacris", "The Red Light District", 2004, 4, 13.49 );

    makeCD( "R & B", "2Pac", "Loyal To The Game", 2004, 3.9, 13.49 );

    makeCD( "Rap", "Eminem", "Encore", 2004, 3.5, 15.75 );

    makeCD( "Romantic", "Narayan, Udit", "KNPH", 2004, 3.4, 14.49 );
    makeCD( "Hip Hop", "Honey Singh", "Blue Eyes", 2014, 3.1, 16.49 );

    cout<<"Genre Artist Title Year Stars Price ";
    for(int i=0;i<10;i++){ //display CD data
        cout<<c[i].genere<<" "<<c[i].artist<<" "<<c[i].title<<" "<<c[i].year<<" "<<c[i].stars<<" "<<c[i].price<<" ";
    }
    system("pause");    //wait at console for any key to be pressed
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote