Created
October 26, 2015 12:46
-
-
Save dralletje/26969b5634f885afa802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <cstdlib> | |
#include <cassert> | |
using namespace std; | |
struct Length | |
{ | |
int minutes; // #minuten (0..) | |
int seconds; // #seconden (0..59) | |
}; | |
struct Track | |
{ | |
string artist; // naam van uitvoerende artiest | |
string cd; // titel van cd | |
int year; // jaar van uitgave | |
int track; // nummer van track | |
string title; // titel van track | |
string tags; // tags van track | |
Length time; // lengte van track | |
string country; // land van artiest | |
}; | |
struct TrackDisplay | |
{ | |
bool showArtist; // toont artist als true | |
bool showAlbum; // toont cd titel als true | |
bool showYear; // toont year als true | |
bool showTrack; // toont track nr als true | |
bool showTitle; // toont track titel als true | |
bool showTags; // toont tags als true | |
bool showLength; // toont track lengte als true | |
bool showCountry; // toont country als true | |
}; | |
bool match (string sub, string source) | |
{// Preconditie: | |
assert (true) ; | |
/* Postconditie: | |
Resultaat is true alleen als sub een letterlijke (case-sensitive) deelstring is van source. | |
*/ | |
return source.find(sub) != string::npos ; | |
} | |
ostream& operator<< (ostream& out, const Length lengte) { | |
out << lengte.minutes << ':' << lengte.seconds; | |
return out; | |
} | |
istream& operator>> (istream& in, Length& lengte) { | |
string alles; | |
in >> alles; | |
string minuten; | |
string seconden; | |
bool minuut = true; | |
for(int i = 0; i < alles.size(); i = i + 1) { | |
if (alles[i] == ':') { | |
minuut = false; | |
continue; | |
} | |
if (minuut) { | |
minuten = minuten + alles[i]; | |
} else { | |
seconden = seconden + alles[i]; | |
} | |
} | |
lengte.seconds = stoi(seconden); | |
lengte.minutes = stoi(minuten); | |
return in; | |
} | |
Length operator+ (const Length& a, const Length& b) { | |
assert (0 <= a.minutes && 0 <= a.seconds && a.seconds < 60 && 0 <= b.minutes && 0 <= b.seconds && b.seconds < 60) ; | |
Length newLength; | |
int tempSeconds = a.seconds + b.seconds; | |
int tempMinutes = a.minutes + b.minutes; | |
if (tempSeconds > 60) { | |
newLength.seconds = tempSeconds % 60; | |
newLength.minutes = tempMinutes + 1; | |
} else { | |
newLength.seconds = tempSeconds; | |
newLength.minutes = tempMinutes; | |
} | |
return newLength; | |
} | |
void show_track (Track lied, TrackDisplay lt) { | |
if (lt.showArtist) { | |
cout << "artist: " << lied.artist << '\n'; | |
} | |
if (lt.showAlbum) { | |
cout << "cd: " << lied.cd << '\n'; | |
} | |
if (lt.showYear) { | |
cout << "year: " << lied.year << '\n'; | |
} | |
if (lt.showTrack) { | |
cout << "track: "; | |
if (lied.track < 10) { | |
cout << "0" << lied.track; | |
} else { | |
cout << lied.track; | |
} | |
cout << '\n'; | |
} | |
if (lt.showTitle) { | |
cout << "title: " << lied.title << '\n'; | |
} | |
if (lt.showTags) { | |
cout << "tags: " << lied.tags << '\n'; | |
} | |
if (lt.showLength) { | |
cout << "time: " << lied.time << '\n'; | |
} | |
if (lt.showCountry) { | |
cout << "country: " << lied.country << '\n'; | |
} | |
} | |
istream& operator>> (istream& in, Track& track) | |
{// Preconditie: | |
assert (true) ; | |
/* Postconditie: | |
De inhoud van de eerstvolgende 8 regels uit in zijn gelezen en omgezet naar de corresponderende members in track. | |
De daaropvolgende (lege) regel uit in is ook gelezen. | |
*/ | |
} | |
const int MAX_NR_OF_TRACKS = 5000; | |
typedef Track MusicDB [MAX_NR_OF_TRACKS]; | |
int main() { | |
Track test = {"Adele","19",2008,1,"Daydreamer","pop,debut album",{3,40},"England"}; | |
TrackDisplay display = {true, true, true, true, true, true, true, true}; | |
show_track(test, display); | |
/* Postconditie: | |
De muziekdatabase "Nummers.txt" is (indien aanwezig en correct geformatteerd) ingelezen. | |
De gebruiker is in staat geweest database queries te stellen en heeft de antwoorden op deze | |
queries gezien. | |
*/ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment