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

PYTHON PROGRAM: read from txt file and output (THIS PROGRAM SHOULD BE USING DICT

ID: 3592130 • Letter: P

Question

PYTHON PROGRAM: read from txt file and output (THIS PROGRAM SHOULD BE USING DICTIONARIES)

Note: None value is not a string but a special value.

men0.txt

m1;w3;w2;w1
m2;w3;w1;w2
m3;w2;w1;w3

women0.txt

w1;m1;m2;m3
w2;m2;m1;m3
w3;m3;m2;m1

Functions:

def read_match_preferences(open_file : open) -> {str:[str,[str]]}:

def dict_as_str(d : {str:[str,[str]]}, key : callable=None, reverse : bool=False) -> str:

My attempted functions:

My Main Function:

Read files of men and women and their rankings of all members of the opposite gender (highest to lowest preference), separated by semicolons, building a dictionary like the ones above (where each match is initially the special value None). As described above, we annotate the structure of this dictionary as {str:[str,[str) In the file, the person's name appears first, followed by the names of all members of the opposite gender in highest to lowest preference, separated by one semicolon character. For example, the input file men0.txt contains the following lines: these line could appear in this order, or any other, but the each man's preferences must appear in decleasing order of preference The first line means, ml ranks the members of the opposite gender in the order of preference from w3, w2, and wl in decreasing order of preference Each line is guaranteed to start with a unique name, which is guaranteed to be followed by all the names of all members of the opposite gender, each appearing once; and all names are separated by semicolons When you print such information, print each person on a separate line, followed by his/her match and preferences. For example, the file above would print as m1 - [None, ['w3', W2', m2 [None, ['w3' m3[None, ['w2', 'i', w3']] Note that the names on the lines must be sorted in alphabetical order, the list of preferences must appear in the same order they appeared in the file. There are multiple pairs of data files for this program, all named like men0.txt and women0.txt; Test/debug your program on the first file; when you are done, test it on the remaining files.

Explanation / Answer

//Song Class

#ifndef SONG_CLASS

#define SONG_CLASS

using namespace std;

class Song

{

private:

        string title; //dynamic allocation

        string album;

        string genre;

        string artist;

        double durationn;

public:

        Song();

        void setTitle(string t);

        void setDuration(double d);

        void setAlbumName(string a);

        void setGenre(string g);

        void setArtist(string a);

        string getTitle();

        string getAlbum()const;

        string getGenre()const;

        string getArtist()const;

        double getDuration)(); //accessor

};

//constructor

Song::Song() //constructor

{

        title="";

        album="";

        genre="";

        artist="";

        duration=0;

}

//accessor for name

string Song::getTitle()

{

return title;

}

//mutator

void Song::setTitle(string t)

{

title=t;

}

//accessor for name

string Song::getAlbum()

{

return album;

}

//mutator

void Song::setAlbumName(string a)

{

album=a;

}

//accessor for name

string Song::getGenre()

{

return genre;

}

//mutator

void Song::setGenre(string g)

{

genre=g;

}

//accessor for name

string Song::getArtist()

{

return artist;

}

//mutator

void Song::setArtist(string s)

{

artist=s;

}

void Song::setDuration(double d)

{

duration=d;

}

double Song::getDuration()

{

return duration;

}

#endif   // SONG_CLASS

//FOR THE .CPP

I DO NOT KNOW HOW TO DISPLAY IT THERE.

CAN ANYONE HELP?

//file test.cpp

#include <iostream>

#include <fstream>

#include <string>

#include "song.h"

using namespace std;

int main()

{

        return 0;

}

Edit & Run

//Song Class

#ifndef SONG_CLASS

#define SONG_CLASS

using namespace std;

class Song

{

private:

        string title; //dynamic allocation

        string album;

        string genre;

        string artist;

        double durationn;

public:

        Song();

        void setTitle(string t);

        void setDuration(double d);

        void setAlbumName(string a);

        void setGenre(string g);

        void setArtist(string a);

        string getTitle();

        string getAlbum()const;

        string getGenre()const;

        string getArtist()const;

        double getDuration)(); //accessor

};

//constructor

Song::Song() //constructor

{

        title="";

        album="";

        genre="";

        artist="";

        duration=0;

}

//accessor for name

string Song::getTitle()

{

return title;

}

//mutator

void Song::setTitle(string t)

{

title=t;

}

//accessor for name

string Song::getAlbum()

{

return album;

}

//mutator

void Song::setAlbumName(string a)

{

album=a;

}

//accessor for name

string Song::getGenre()

{

return genre;

}

//mutator

void Song::setGenre(string g)

{

genre=g;

}

//accessor for name

string Song::getArtist()

{

return artist;

}

//mutator

void Song::setArtist(string s)

{

artist=s;

}

void Song::setDuration(double d)

{

duration=d;

}

double Song::getDuration()

{

return duration;

}

#endif   // SONG_CLASS

//FOR THE .CPP

I DO NOT KNOW HOW TO DISPLAY IT THERE.

CAN ANYONE HELP?

//file test.cpp

#include <iostream>

#include <fstream>

#include <string>

#include "song.h"

using namespace std;

int main()

{

        return 0;

}

Edit & Run