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

Write a program that allows the user to enter 10 songs and their artists into a

ID: 3699367 • Letter: W

Question

Write a program that allows the user to enter 10 songs and their artists into a playlist and will sort the entires by artist order. The program should use a 10 element array of structure objects that holds two string variables: artist and title. Once the data has been read in and stored, it should sort the entries in the ascending order by artist. It should then display the sorted array with appropriate headings. Write a program that allows the user to enter 10 songs and their artists into a playlist and will sort the entires by artist order. The program should use a 10 element array of structure objects that holds two string variables: artist and title. Once the data has been read in and stored, it should sort the entries in the ascending order by artist. It should then display the sorted array with appropriate headings.

Explanation / Answer

#include <stdio.h>

#include <string.h>

struct song{

char title[1000];

char artist[1000];

};

int main(){

struct song data[10];

struct song temp;

int i,j,n=10;

//taking input

for(i=0;i<n;i++){

printf("Enter title:");

gets(data[i].title);

printf("Enter artist:");

gets(data[i].artist);

}

//sorting the structure array by artist

for(i=0;i<n-1;i++){

for(j=i+1;j<n;j++){

if(strcmp(data[i].artist,data[j].artist)>0){

temp=data[i];

data[i]=data[j];

data[j]=temp;

}

}

}

printf("After sorting in ascending order by artist ");

printf("Song Title Song Artist ");

printf("---------- ----------- ");

//printing the sorted structure by array

for(i=0;i<n;i++){

printf("%s ",data[i].title);

printf("%s ",data[i].artist);fg

}

return 0;

}

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