I need the program written in C# There are included several pages of the LAB tas
ID: 3820860 • Letter: I
Question
I need the program written in C#
There are included several pages of the LAB task C programming
also text file with data.
I found here already done programs written in C++ but I don't know how to makeover them
page1
page 3
Selection Sort C Code
void selection_sort( int a[], int size )
{
int i, j, temporary, minimum;
for ( i = 0; i < size - 1; i++ ) {
minimum = i; // list the first entry as the default minimum
for ( j = i + 1; j < size; j++ ) // traverse the array and find the minimum
if ( a[ minimum ] > a[j]) minimum = j; // found a smaller one, so make it the minimum
// perform the swap of the data
temporary = a[i];
a[i] = a[ minimum ];
a[ minimum ] = temporary;
}
return;
}
Bubble Sort C Code
void bubble_sort( int a[ ], int n )
{
int i, j, temporary;
for( i = 0; i < n – 1; i++ )
for ( j = 0; j < n – i – 1; j++ )
if ( a[ j ] > a[ j + 1 ] )
{ temporary = data[ j ];
data[ j ] = data[ j + 1 ];
data[ j + 1 ] = temporary;
}
return;
}
Text File:
Splish Splash Bobby Darin 153 At The Hop Danny & The Juniors 135 16 Candles The Crests 213 Rockin' Robin Bobby Day 178 Wake Up Little Susie The Everly Brothers 151 Rock Around The Clock Bill Haley & His Comets 168 Earth Angel The Penguins 136 That'll Be The Day Buddy Holly & The Crickets 147 Little Darlin' The Diamonds 181 Blueberry Hill Fats Domino 178 Long Tall Sally Little Richard 156 Yakety Yak The Coasters 181 Donna Ritchie Valens 178 Tequila The Champs 171 Do You Wanna Dance Bobby Freeman 183 The Great Pretender The Platters 178 Blue Suede Shoes Carl Perkins 183 Why Do Fools Fall In Love Frankie Lymon & The Teenagers 198 Tears On My Pillow Little Anthony & The Imperials 181 Great Balls Of Fire Jerry Lee Lewis 177 Things Bobby Darin 176 Monster Mash Bobby (Boris) Pickett 189 Blame It On The Bossa Nova Edyie Gorme 238 Sealed With A Kiss Brian Hyland 183 I Can't Stop Loving You Ray Charles 180 Let's Dance Chris Montez 156 Love Me Tender Richard Chamberlain 188 Dance On Little Girl Paul Anka 263 At Last Etta James 269 Together Connie Francis 229 Go Away Little Girl Steve Lawrence 183 Paper Roses Paul Anka 228 Does Your Chewing Gum Lose It's Flavor Lonnie Donegan 182 * Billboard’s Top 40 Best Pop Songs of 2015 Uptown Funk! Mark Ronson Featuring Bruno Mars 302 See You Again Wiz Khalifa Featuring Charlie Puth 393 Trap Queen Fetty Wap 281 Sugar Maroon 5 303 Shut Up And Dance Walk the Moon 399 Blank Space Taylor Swift 271 Watch Me Silent 303 Earned It The Weeknd 218 The Hills The Weeked 203 Cheerleader OMI 410 Can’t Feel My Face The Weeknd 343 Love Me Like You Do Ellie Goulding 202 Take Me To Church Hozier 363 Bad Blood Taylor Swift Featuring Kendrick Lamar 300 Lean On Major Lazer & DJ Snake featuring M0 502 Want To Want Me Jason Derulo 478 Shake It Off Taylor Swift 287 Where Are U Now Skrillex & Diplo with Justin Bieber 412 Fight Song Rachel Platten 382 679 Fetty Wap Featuring Remy Boyz 488 Lips Are Movin Meghan Trainor 356 Worth It Fifth Harmony Featuring Kid Ink 401 Post To Be Omarion Featuring Chris Brown & Jhene Aiko 339 Honey, I’m Good Andy Grammer 333 I’m Not The Only One Sam Smith 288 Good For You Selena Gomez featuring A$AP Rocky 513 All About That Bass Meghan Trainor 302 Style Taylor Swift 379 Hotline Bling Drake 403 Hey Mama David Guetta Featuring Nicki Minaj, Bebe Rexha & Afrojack 471 G.D.F.R. Flo Rida Featuring Sage The Gemini & Lookas 361 What Do You Mean? Justin Bieber 302 Photograph Ed Sheehan 356 Hello Adele 467 Stitches Shawn Mendes 298 Talking Body Tove Lo 418 Jealous Nick Jonas 320 Time Of Our Lives Pitbull & Ne-Yo 396 Locked Away R. City Featuring Adam Levine 351 * Johnny Cash Greatest Hits Man In Black Johnny Cash 178 Rusty Cage Johnny Cash 203 A Boy Named Sue Johnny Cash 186 One Piece at a Time Johnny Cash 203 Jackson Johnny Cash 188 Sunday Morning Coming Down Johnny Cash 209 Hurt Johnny Cash 224 Ring of Fire Johnny Cash 202 Folsom Prison Blues Johnny Cash 212 I Walk The Line Johnny Cash 234 Prerequisites: Read Chapter 11 in the textbook before attempting this lab. Problem Specification: Read in the data from a file about the music contained on an album and display it in a format that is easy for humans to see and read. Use a structure to read in your data. After reading it in, display a count of the number of tracks (songs) and the total time for all songs read in. Then prompt for a sorting key twhich will be either song title, artist, or length) and a sequence tascending or descending and then print them out, so they look something like Track Title Artist Time The Beatles 2: 18 Help 3:10 2. Ticket To Ride The Beatles Use whatever the key was as the first thing displayed. So, if I requested sorting by time, it would look like Title Track Time Artist The Beatles 1 2 18 Help! 3:10 Ticket To Ride The BeatlesExplanation / Answer
/* Please do upvote if you like it :) */
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace MusicManager
{
class MusicManager
{
private List<Music> albumList;
public MusicManager(string filePath) {
albumList = readFromFile(filePath);
startUserInteraction();
}
public static void Main(string[] args) {
MusicManager manager = new MusicManager("/home/zubair/Desktop/pythonProg/csharp/music.txt");
}
public List<Music> readFromFile(string filePath)
{
List<Music> albumList = new List<Music>();
StreamReader reader = File.OpenText(filePath);
Console.WriteLine("checkpoint reading -1 ");
string line;
bool flag = true;
while (true) {
string[] trackData = new string[3];
for (int i=0; i<3; i++)
{
if ((line = reader.ReadLine()) != null)
{
trackData[i] = line;
}
else
{
flag = false; break;
}
}
if (flag == false)
{
break;
}
Music track = new Music(trackData[0], trackData[1], int.Parse(trackData[2]));
albumList.Add(track);
}
return albumList;
}
public void startUserInteraction()
{
while (true) {
int choiceOne;
printMenuOne();
if (int.TryParse(Console.ReadLine(), out choiceOne))
{
if (choiceOne > 4 || choiceOne < 0) {
Console.WriteLine(" Invalid Choice!");
continue;
}
if (choiceOne == 4) {
return;
}
printMenuTwo();
int choiceTwo;
if (int.TryParse(Console.ReadLine(), out choiceTwo))
{
if (choiceTwo > 2 || choiceTwo < 1) {
Console.WriteLine(" Invalid Choice!");
continue;
}
if (choiceOne == 1 && choiceTwo == 1) {
List<Music> newList = albumList.OrderBy(o=>o.title).ToList();
printOutput(newList, choiceOne);
}
else if (choiceOne == 1 && choiceTwo == 2) {
List<Music> newList = albumList.OrderByDescending(o=>o.title).ToList();
printOutput(newList, choiceOne);
}
if (choiceOne == 2 && choiceTwo == 1) {
List<Music> newList = albumList.OrderBy(o=>o.artist).ToList();
printOutput(newList, choiceOne);
}
else if (choiceOne == 2 && choiceTwo == 2) {
List<Music> newList = albumList.OrderByDescending(o=>o.artist).ToList();
printOutput(newList, choiceOne);
}
if (choiceOne == 3 && choiceTwo == 1) {
List<Music> newList = albumList.OrderBy(o=>o.length).ToList();
printOutput(newList, choiceOne);
}
else if (choiceOne == 3 && choiceTwo == 2) {
List<Music> newList = albumList.OrderByDescending(o=>o.length).ToList();
printOutput(newList, choiceOne);
}
}
else
{
return;
}
}
else
{
return;
}
}
}
public void printOutput(List<Music> musicList, int key)
{
string format = "{0,-15} {1,-15} {2,-15} {3, -15}";
if (key == 1) {
string[] heading = new string[] { "Track Number", "Title", "Artist", "Length" };
Console.WriteLine(string.Format(format, heading));
}
else if (key == 2) {
string[] heading = new string[] { "Track Number", "Artist", "Artist", "Length" };
Console.WriteLine(string.Format(format, heading));
}
else if (key == 3) {
string[] heading = new string[] { "Track Number", "Length", "Title", "Artist" };
Console.WriteLine(string.Format(format, heading));
}
else {
return;
}
Console.WriteLine(" ");
for (int i=0; i<musicList.Count; i++) {
Music mtrack = musicList[i];
string title = mtrack.title;
string artist = mtrack.artist;
int minutes = mtrack.length/60;
int seconds = mtrack.length%60;
string length = minutes +":" + seconds;
string index = (i+1) + ".";
if (key == 1) {
string[] data = new string[] { index, title, artist, length};
Console.WriteLine(string.Format(format, data));
}
if (key == 2) {
string[] data = new string[] { index, artist, title, length};
Console.WriteLine(string.Format(format, data));
}
if (key == 3) {
string[] data = new string[] { index, length, title, artist};
Console.WriteLine(string.Format(format, data));
}
}
}
public void printMenuOne() {
Console.WriteLine(" Choose one of the sorting key");
Console.WriteLine("1. Title");
Console.WriteLine("2. Aritst");
Console.WriteLine("3. Length");
Console.WriteLine("4. Exit");
Console.Write("Enter your choice (int) : ");
}
public void printMenuTwo() {
Console.WriteLine(" How do you want us to sort? ");
Console.WriteLine("1. Ascending order");
Console.WriteLine("2. Descending order");
Console.Write("Enter your choice (int) : ");
}
}
class Music
{
public string title { get; set; }
public string artist { get; set; }
public int length { get; set; }
public string toString() {
return "[Title = " + title + ", Artist = " + artist + ", Length = " + length + "]";
}
public Music(string title, string artist, int length)
{
this.title = title;
this.artist = artist;
this.length = length;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.