Help Me With C++?

science

science rules
OP
Member
Joined
Jun 9, 2006
Messages
3,697
Trophies
1
Age
33
XP
1,249
Country
Canada
Hey guys, I have an assignment due tomorrow that I will have to do tonight because I have class all day tomorrow. If you saw my other blog, you know how stressed I am about this stuff. But I really want to get this stuff, so I don't just want someone to do it for me. If I even get half this thing working I'll be happy.

Here is the assignment: http://www.cs.uleth.ca/~bomhof/cs2620A/assn/assn1.txt

And all I have so far is a list of things I need to implement, no actual code.

What I think I need:

A function that creates the picture. I think I will need some vectors that accept strings in this function.

A Draw function that draws the picture.

a frameIt function that draws the frame. It depends on a function called isFramed that determines if there is a frame or not.

A unFrameIt function that draws no frame. It also depends on isFramed.

isFramed returns a boolean type and a frame character.

I think that is everything I need.

I don't want to dive in and do this all at once. I want to take baby steps. If I could get the vectors reading in strings and printing out strings, I'll be happy.

And here is what I think I would do to do that...

write a class called CharacterPicture, so..

class CharacterPicture {
public:
vector iVec();
};

And then in my .cc file, have something like...

cout
 

chuckstudios

Putting the pro in procrastination
Member
Joined
Jul 19, 2006
Messages
890
Trophies
0
Age
124
Location
North Carolina, USA
Website
www.schlarp.com
XP
275
Country
United States
clipboard01dd4.png
 

chuckstudios

Putting the pro in procrastination
Member
Joined
Jul 19, 2006
Messages
890
Trophies
0
Age
124
Location
North Carolina, USA
Website
www.schlarp.com
XP
275
Country
United States
CODE#include
#include
#include
#include
#include

using namespace std;

class CharacterPicture
{
ÂÂÂÂprivate:
ÂÂÂÂÂÂÂÂ// Character used when printing the frame
ÂÂÂÂÂÂÂÂstring frameCharacter;
ÂÂÂÂÂÂÂÂ// Vector used to store all strings in the object
ÂÂÂÂÂÂÂÂvector pictureStrings;
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ// Returns the longest string contained in the object
ÂÂÂÂÂÂÂÂ// *** Not required by spec, but makes life a lot easier during
ÂÂÂÂÂÂÂÂ//ÂÂÂÂ framing and concatenation by determining how far to frame or pad
ÂÂÂÂÂÂÂÂint longestString();
ÂÂÂÂpublic:
ÂÂÂÂÂÂÂÂ// Create a new CharacterPicture object
ÂÂÂÂÂÂÂÂCharacterPicture();
ÂÂÂÂÂÂÂÂ// Create a new CharacterPicture object as a copy of another
ÂÂÂÂÂÂÂÂCharacterPicture(CharacterPicture& pic);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ// Returns the number of discrete strings in this object
ÂÂÂÂÂÂÂÂint getSize();
ÂÂÂÂÂÂÂÂ// Returns a string from this object by index
ÂÂÂÂÂÂÂÂstring getString(int index);
ÂÂÂÂÂÂÂÂ// Returns the character used for the frame
ÂÂÂÂÂÂÂÂstring getFrame();
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ// Change the frame character used in output, the default is '*'
ÂÂÂÂÂÂÂÂvoid setFrame(string frame);
ÂÂÂÂÂÂÂÂ// Add a new string to the object
ÂÂÂÂÂÂÂÂ// *** Not required by spec, but simplifies adding with the other two
ÂÂÂÂÂÂÂÂ//ÂÂÂÂ methods. Also has the side effect of making programmatic
ÂÂÂÂÂÂÂÂ//ÂÂÂÂ additions a bit more elegant.
ÂÂÂÂÂÂÂÂvoid addString(string str);
ÂÂÂÂÂÂÂÂ// Add a new string to the object by console input
ÂÂÂÂÂÂÂÂvoid inputString();
ÂÂÂÂÂÂÂÂ// Load strings from a file
ÂÂÂÂÂÂÂÂvoid loadFile(string filename);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ// Concatenate another CharacterPicture object horizontally
ÂÂÂÂÂÂÂÂvoid concatHorizontal(CharacterPicture pic);
ÂÂÂÂÂÂÂÂ// Concatenate another CharacterPicture object vertically
ÂÂÂÂÂÂÂÂvoid concatVertical(CharacterPicture pic);
ÂÂÂÂÂÂÂÂ
ÂÂÂÂÂÂÂÂ// Print the character picture to stdout, takes an optional boolean to
ÂÂÂÂÂÂÂÂ// determine if the frame should be used
ÂÂÂÂÂÂÂÂvoid output(bool frame = false);
ÂÂÂÂÂÂÂÂ// Print the character picture to the filename specified, takes an
ÂÂÂÂÂÂÂÂ// optional boolean to determine if the frame should be used
ÂÂÂÂÂÂÂÂvoid output(string filename, bool frame = false);
};

int CharacterPicture::longestString()
{
ÂÂÂÂint maxlen = 0;
ÂÂÂÂfor(int i = 0; i < getSize(); i++)
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂif(pictureStrings.length() > maxlen)
ÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂmaxlen = pictureStrings.length();
ÂÂÂÂÂÂÂÂ}
ÂÂÂÂ}
ÂÂÂÂreturn maxlen;
}

CharacterPicture::CharacterPicture()
{
ÂÂÂÂsetFrame("*");
}

CharacterPicture::CharacterPicture(CharacterPicture& pic)
{
ÂÂÂÂfor(int i = 0; i < pic.getSize(); i++)
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂaddString(pic.getString(i));
ÂÂÂÂ}
ÂÂÂÂsetFrame(pic.getFrame());
}

int CharacterPicture::getSize()
{
ÂÂÂÂreturn pictureStrings.size();
}

string CharacterPicture::getString(int index)
{
ÂÂÂÂif(index >= 0 && index < getSize())
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂreturn pictureStrings[index];
ÂÂÂÂ}
ÂÂÂÂelse
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂreturn string("");
ÂÂÂÂ}
}

string CharacterPicture::getFrame()
{
ÂÂÂÂreturn frameCharacter;
}

void CharacterPicture::setFrame(string frame)
{
ÂÂÂÂframeCharacter = frame;
}

void CharacterPicture::addString(string str)
{
ÂÂÂÂpictureStrings.push_back(str);
}

void CharacterPicture::inputString()
{
ÂÂÂÂchar str[256];
ÂÂÂÂcin.getline(str, 256);
ÂÂÂÂaddString(string(str));
}

void CharacterPicture::loadFile(string filename)
{
ÂÂÂÂstring line;
ÂÂÂÂifstream stringfile(filename.c_str());
ÂÂÂÂif(stringfile.is_open())
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂ while(!stringfile.eof())
ÂÂÂÂÂÂÂÂ {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ getline(stringfile, line);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ addString(line);
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ stringfile.close();
ÂÂÂÂ}
}

void CharacterPicture::concatHorizontal(CharacterPicture pic)
{
ÂÂÂÂint length = longestString() + 1;
ÂÂÂÂfor(int i = 0; i < pic.getSize(); i++)
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂif(i < getSize())
ÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂstring str;
ÂÂÂÂÂÂÂÂÂÂÂÂstr = pictureStrings;
ÂÂÂÂÂÂÂÂÂÂÂÂstr.resize(length, ' ');
ÂÂÂÂÂÂÂÂÂÂÂÂstr += pic.getString(i);
ÂÂÂÂÂÂÂÂÂÂÂÂpictureStrings = str;
ÂÂÂÂÂÂÂÂ}
ÂÂÂÂÂÂÂÂelse
ÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂstring str;
ÂÂÂÂÂÂÂÂÂÂÂÂstr.resize(length, ' ');
ÂÂÂÂÂÂÂÂÂÂÂÂpictureStrings.push_back(str + pic.getString(i));
ÂÂÂÂÂÂÂÂ}
ÂÂÂÂ}
}

void CharacterPicture::concatVertical(CharacterPicture pic)
{
ÂÂÂÂfor(int i = 0; i < pic.getSize(); i++)
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂpictureStrings.push_back(pic.getString(i));
ÂÂÂÂ}
}

void CharacterPicture::output(bool frame)
{
ÂÂÂÂif(frame)
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂfor(int i = 0; i < (longestString() + 4); i++)
ÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂcout
 

Psyfira

Credit: 0ml. Insert tea to continue
Member
Joined
Dec 31, 2003
Messages
3,886
Trophies
0
Location
England
XP
270
Country
What the hell Chuck, he said he wanted someone to help him understand the concepts and the gist of it, not write the whole thing and rub it in his face
mad.gif
 

science

science rules
OP
Member
Joined
Jun 9, 2006
Messages
3,697
Trophies
1
Age
33
XP
1,249
Country
Canada
Psyfira said:
What the hell Chuck, he said he wanted someone to help him understand the concepts and the gist of it, not write the whole thing and rub it in his face
mad.gif

Yeah thats what I wanted, but I do want to learn this stuff, so I'm not just going to hand in his code. I'm going to use it to ask my own questions like "How would I do this?" and then check the answers. Kinda like a study guide. It should help a bit. Thanks a lot chuck
 

Jeremysr

Member
Newcomer
Joined
Jul 26, 2006
Messages
21
Trophies
0
Age
32
Location
Kamsack, Saskatchewan, Canada
Website
viewsourcecode.org
XP
229
Country
Canada
Heh, some people just can't resist solving every small programming problem they come across.
tongue.gif
I've saved the assignment text to my computer for the next time I really want to program but have nothing to program (which happens quite often.)

science: If you have any more C++ questions, I'll be happy to help.
smile.gif
Not sure if you still need help with this.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    HiradeGirl @ HiradeGirl: Thanks, dear. @K3Nv2