Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Eric

Eric Avatar



1,442


November 2005
Who else here codes in C++? I've recently been really starting to kick myself for not practicing my C++ and for not learning more. I'm still a n00b, but meh, everyone starts somewhere.

Here's a program I just recently made to test out pointers and classes:
#include <iostream>

class Song
{
   private:
      std::string name;
      int length;
   public:
      Song(std :: string iName);
      ~Song();
      std :: string getName();
      void setName(std :: string sName);
      int getLength();
      void setLength(int sLen);
};
Song :: Song(std :: string iName = "")
{
   name = iName;
}
Song :: ~Song(){}
std :: string Song :: getName()
{
   return name;
}
void Song :: setName(std :: string sName)
{
   name = sName;
}
int Song :: getLength()
{
   return length;
}
void Song :: setLength(int sLen)
{
   length = sLen;
}

class Album
{
   private:
      std :: string title;
      Song songs[50];
      int numSongs;
   public:
      Album(std :: string iTitle);
      ~Album();
      Song* getSongs();
      void addSong(std :: string name, int time);
      void setTitle(std :: string sTitle);
      std :: string getTitle();
      void clearSongs();
      int getNumSongs();
};
Album :: Album(std :: string iTitle = "")
{
   setTitle(iTitle);
   numSongs = 0;
}
Album :: ~Album(){}
Song* Album :: getSongs()
{
   return &songs[0];
}
void Album :: addSong(std :: string name, int time)
{
   songs[numSongs].setName(name);
   songs[numSongs].setLength(time);
   numSongs++;
}
void Album :: setTitle(std :: string sTitle)
{
   title = sTitle;
}
std :: string Album :: getTitle()
{
   return title;
}
void Album :: clearSongs()
{
   delete songs;
   Song songs[50];
   numSongs = 0;
}
int Album :: getNumSongs()
{
   return numSongs;
}

int main()
{
   Album eRock("Eric's Rock CD");
   eRock.addSong("Foobar", 5);
   eRock.addSong("Booga Booga", 3);
   Song* eSongs = eRock.getSongs();
   for(int s = 0; s < eRock.getNumSongs(); s++)
   {
      std :: cout << eSongs.getName() + "\n";
   }
   std :: cout << eRock.getTitle() + "\n";
   system("PAUSE");
}



Last Edit: Nov 26, 2005 21:07:09 GMT by Eric

hey

hey Avatar
j00 n00b. =P

**
Official Member

50


October 2005
I plan to learn it, but I'm beginning to learn Java right now (applets and applications).

This will divide numbers (yeah, that's all I know for applications):

public class hey {
    public static void main (String[] args){
        int num1 = 64;
        int num2 = 5;

        double divide = 64 / 5;

        System.out.println(divide);
    }
}

I'll post something for applets later.


Last Edit: Nov 27, 2005 4:57:17 GMT by hey
forums.talesrpg.com

newBookmarkLockedFalling