I need assistance in Programing Language C What we are suppo
I need assistance in Programing, Language C. What we are suppose to do with this code is....
- Change the struct card from the attached file to struct song with the following fields:
char array artist
char array songName
int for the length in seconds
double cost
Modify all variable declarations, function prototypes, and functions calls to reflect the changes from card to song
For the array of songs use the variable playlist (instead of manycards)
The code that is being alternate is...
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#define SIZE 20
typedef struct{
char face[SIZE];
char suit[SIZE];
int pointV;
}card;
//Function Prototypes
// fills the data fields of a card instance
//returns the filled card
card FillCard();
//fills the data fields of a card instance
//by reference using a pointer to a card
void FillCardPtr(card *cardptr);
//fills an array of cards
void FillCardArray(card arrayC[], int *size);
//displays one card
void DisplayCard(card anyCard);
int main()
{
//Declare variables
card myCard, myCard1, myCard2;
card manyCards[SIZE];
int cSize;
int i;
//Fill structures with a function
myCard = FillCard();
myCard1 = FillCard();
//print using display function
printf(\"\ ---------Display myCard\ \");
DisplayCard(myCard);
printf(\"\ ---------Display myCard1\ \");
DisplayCard(myCard1);
//Fill structure using pointers and dispay it
FillCardPtr(&myCard2);
printf(\"\ ---------Display myCard2\ \");
DisplayCard(myCard2);
//Fill the array with the function
printf(\"\ ---------Fill array manyCards\ \");
FillCardArray(manyCards, &cSize);
//display an array of cards
printf(\"\ ---------Display array manyCards\ \");
for(i=0;i<cSize; i++)
{
DisplayCard(manyCards[i]);
}
return 0;
}
//Function Definitions
// fills the data fields of a card instance
//returns the filled card
card FillCard()
{
//Declare local variables
card tempC;
//prompt and get information
printf(\"\ please enter the face of your card: \");
scanf(\"%s\", tempC.face);
//print to check
printf(\"face: %s\ \", tempC.face);
//prompt and get information
printf(\"\ please enter the suit of your card: \");
scanf(\"%s\", tempC.suit);
//print to check
printf(\"suit: %s\ \", tempC.suit);
//prompt and get information
printf(\"\ please enter the point value of your card: \");
scanf(\"%d\", &tempC.pointV);
printf(\"point value: %d\ \", tempC.pointV);
return tempC;
}
//displays one card
void DisplayCard(card anyCard)
{
printf(\"\ \ face: %s\ \", anyCard.face);
printf(\"suit: %s\ \", anyCard.suit);
printf(\"point value: %d\ \", anyCard.pointV);
}
//fills the data fields of a card instance
//by reference using a pointer to a card
void FillCardPtr(card *cardptr)
{
//prompt and get information
printf(\"\ please enter the face of your card: \");
scanf(\"%s\", (*cardptr).face);
//prompt and get information
printf(\"\ please enter the suit of your card: \");
scanf(\"%s\", cardptr->suit);
//prompt and get information
printf(\"\ please enter the point value of your card: \");
scanf(\"%d\", &(*cardptr).pointV);
}
//fills an array of cards
void FillCardArray(card arrayC[], int *size)
{
int i;
//prompt the user
printf(\"\ enter the number of cards: \");
scanf(\"%d\", size);
//print to check
printf(\"size: %d\ \", *size);
for (i=0; i < *size; i++)
{
printf(\"enter face: \");
scanf(\"%s\", arrayC[i].face);
printf(\"enter suit: \");
scanf(\"%s\", arrayC[i].suit);
printf(\"enter point value: \");
scanf(\"%d\", &arrayC[i].pointV);
}
}
/*please enter the face of your card: king
face: king
please enter the suit of your card: spade
suit: spade
please enter the point value of your card: 10
point value: 10
please enter the face of your card: three
face: three
please enter the suit of your card: heart
suit: heart
please enter the point value of your card: 3
point value: 3
---------Display myCard
face: king
suit: spade
point value: 10
---------Display myCard1
face: three
suit: heart
point value: 3
please enter the face of your card: king
please enter the suit of your card: diamonds
please enter the point value of your card: 10
---------Display myCard2
face: king
suit: diamonds
point value: 10
---------Fill array manyCards
enter the number of cards: 3
size: 3
enter face: jack
enter suit: clubs
enter point value: 10
enter face: four
enter suit: hearts
enter point value: 4
enter face: ace
enter suit: spades
enter point value: 11
---------Display array manyCards
face: jack
suit: clubs
point value: 10
face: four
suit: hearts
point value: 4
face: ace
suit: spades
point value: 11
Press any key to continue . . .*/
Please assist in the alteration\'s, Thank you.
Solution
/*This code works perfectly Fine with all the replacements as mentioned above I have tested in my local machine it was working fine as expected*/
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#define SIZE 20
typedef struct{
char artist[SIZE];
char songName[SIZE];
int length;
}song;
//Function Prototypes
// fills the data fields of a song instance
//returns the filled song
song FillSong();
//fills the data fields of a song instance
//by reference using a pointer to a song
void FillSongPtr(song *songptr);
//fills an array of songs
void FillSongArray(song arrayC[], int *size);
//displays one song
void DisplaySong(song anySong);
int main()
{
//Declare variables
song mySong, mySong1, mySong2;
song manySongs[SIZE];
int cSize;
int i;
//Fill structures with a function
mySong = FillSong();
mySong1 = FillSong();
//print using display function
printf(\"\ ---------Display mySong\ \");
DisplaySong(mySong);
printf(\"\ ---------Display mySong1\ \");
DisplaySong(mySong1);
//Fill structure using pointers and dispay it
FillSongPtr(&mySong2);
printf(\"\ ---------Display mySong2\ \");
DisplaySong(mySong2);
//Fill the array with the function
printf(\"\ ---------Fill array manySongs\ \");
FillSongArray(manySongs, &cSize);
//display an array of songs
printf(\"\ ---------Display array manySongs\ \");
for(i=0;i<cSize; i++)
{
DisplaySong(manySongs[i]);
}
return 0;
}
//Function Definitions
// fills the data fields of a song instance
//returns the filled song
song FillSong()
{
//Declare local variables
song tempC;
//prompt and get information
printf(\"\ please enter the artist of your song: \");
scanf(\"%s\", tempC.artist);
//print to check
printf(\"artist: %s\ \", tempC.artist);
//prompt and get information
printf(\"\ please enter the songName of your song: \");
scanf(\"%s\", tempC.songName);
//print to check
printf(\"songName: %s\ \", tempC.songName);
//prompt and get information
printf(\"\ please enter the point value of your song: \");
scanf(\"%d\", &tempC.length);
printf(\"point value: %d\ \", tempC.length);
return tempC;
}
//displays one song
void DisplaySong(song anySong)
{
printf(\"\ \ artist: %s\ \", anySong.artist);
printf(\"songName: %s\ \", anySong.songName);
printf(\"point value: %d\ \", anySong.length);
}
//fills the data fields of a song instance
//by reference using a pointer to a song
void FillSongPtr(song *songptr)
{
//prompt and get information
printf(\"\ please enter the artist of your song: \");
scanf(\"%s\", (*songptr).artist);
//prompt and get information
printf(\"\ please enter the songName of your song: \");
scanf(\"%s\", songptr->songName);
//prompt and get information
printf(\"\ please enter the point value of your song: \");
scanf(\"%d\", &(*songptr).length);
}
//fills an array of songs
void FillSongArray(song arrayC[], int *size)
{
int i;
//prompt the user
printf(\"\ enter the number of songs: \");
scanf(\"%d\", size);
//print to check
printf(\"size: %d\ \", *size);
for (i=0; i < *size; i++)
{
printf(\"enter artist: \");
scanf(\"%s\", arrayC[i].artist);
printf(\"enter songName: \");
scanf(\"%s\", arrayC[i].songName);
printf(\"enter point value: \");
scanf(\"%d\", &arrayC[i].length);
}
}







