d2jsp
Gaming and Trading Community
Gaming and Trading Community
Hourly Raffle
Ladder Slasher
Trade Finder
Photo Gallery
Forum Gold FAQ
Instant Messenger
Help and Rules
Live Streams
Account RecoveryResend Validation Email
Hello, GuestLog InRegister
d2jsp Forums > Programmer's Haven > C/C++/C# > Need Quick C++ Help > Paying, Easy Problem.

Add ReplyNew TopicNew Poll
Page 1 of 1
Aimed_Shot
#1 Jul 5 2012 01:20pm
Group: Members
Posts: 6,306
Joined: Oct 29 2007
Gold: 4.00
200 fg. which I don't have yet but I bought it through paypal and apparently d2jsp has to validate my payment

I fucking hate c++. need full working syntax. this honestly should only require a few lines of code. it must use the class I defined.

the program must prompt the user for the name of the song and then print the information for that song. (name, artist, duration.)

offer is valid for one hour

song.h:

Code
#include <iostream>          
using namespace std;

class Song
{
private:
 string name;
 string artist;
 int duration;

public:
 Song()
 {
   name = "";
   artist = "";
   duration = 0;
 }
 
 void setVars( string, string, int );
 string getName();
 string getArtist();
 int getDuration();
 void Print();

};


song.cpp:
Code
#include "Song.h"      

void Song::setVars( string x, string y, int z )
{
 name = x;
 artist = y;
 duration = z;
}

string Song::getName()
{
 return name;
}

string Song::getArtist()
{
 return artist;
}

int Song::getDuration()
{
 return duration;
}


void Song::Print()
{
 cout << "Name: " << name << endl;
 cout << "Artist: " << artist << endl;
 cout << "Duration: " << duration << "s" << endl;
}


main.cpp:
Code
#include <cstdlib>
#include <iostream>
#include "Song.h"
#include <vector>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
   vector <Song> songVec;
   vector<Song>::iterator it;  
   
   Song a, b, c, d, e, f, g, h, i, j;
 
   songVec.push_back(a);
   songVec[0].setVars("LK", "DJ Marky", 224);
   songVec.push_back(b);
   songVec[1].setVars("Fate or Faith", "Ror Shak", 374);
   songVec.push_back(c);
   songVec[2].setVars("1901", "Phoenix", 204);
   songVec.push_back(d);
   songVec[3].setVars("Hold Your Colour", "Pendulum", 236);
   songVec.push_back(e);
   songVec[4].setVars("Karma", "Guru", 315);
   songVec.push_back(f);
   songVec[5].setVars("Property Is Theft", "Klute", 387);
   songVec.push_back(g);
   songVec[6].setVars("Streetlife", "Chase & Status", 260);
   songVec.push_back(h);
   songVec[7].setVars("Escape", "Netsky", 172);
   songVec.push_back(i);
   songVec[8].setVars("Red Mist", "Danny Byrd", 256);
   songVec.push_back(j);
   songVec[9].setVars("Move For Me", "Kaskade", 279);
   
   string songName;
   cout << "Enter song name: ";
   cin.ignore();
   getline( cin, songName );

//print the song information for the song which has been inputted.

   
   system ("PAUSE");
   return EXIT_SUCCESS;
}


This post was edited by Aimed_Shot on Jul 5 2012 01:28pm
Aimed_Shot
#2 Jul 5 2012 01:44pm
Group: Members
Posts: 6,306
Joined: Oct 29 2007
Gold: 4.00
retract
huskerfan113
#3 Jul 7 2012 03:01am
Group: Members
Posts: 1,050
Joined: Feb 19 2006
Gold: 1,833.69
Don't know if you got this figured out... or if you even care anymore but...

song.h: Add "#include <string>"

main.cpp: add this where your print comment is

Code

//print the song information for the song which has been inputted.
  for ( it = songVec.begin(); it != songVec.end(); ++it )
  {
   if ( songName == *&(*it).getName() )
   {
    (*&(*it)).Print();
    break;
   }
  }


There are much better ways to do this... but without altering the existing code structure this is just a quick and dirty fix

Go Back To C/C++/C# Topic List
Page 1 of 1