I. Dancay said:
Can someone help me work out this project? I need someone who is a
C++ expert to help me work this one out.
Not really. In fact it is a typical homework assignment with
moderate complexity.
But it is this complexity which drives you nuts. This is because
you look at this assignment and say to yourself: Wow, I thats so
much work to do. I even don't know where to start!
Well. Start with the things you can do! The first thing you need
to do, is to derive a plan in which order you want to implement
(and test) things.
You certainly start with
int main()
{
}
That's always a good start
Then you look t the assignment and discover that everything turns
around a 'student'. So you may ask yourself, what denotes a student?
Studying the assignment you figure out, that the description of a student
consists of
first name
last name
credits
grade points
and thats it.
Thus you can start to write (as requested by the assignment) in
a new file called student.h:
class student
{
private:
string first_name;
string last_name;
int credits;
double grade;
};
and you modify your main program to look like this:
#include "student.h"
int main()
{
}
When you try to compile this, you will notice that the compiler will
emit errors on the data type string. It dosn't know what a string
is, you have to tell it:
#include <string>
class student
{
private:
std::string first_name;
std::string last_name;
int credits;
double grade;
};
Compiling again, shows that this fixed the error.
You then continue with what you can write!
Looking through the assignment you see that there has
to be a function 'output()' that should output the
student information to cout. Well write it! I'll wait
To test this function you modify main()
#include <iostream>
#include "student.h"
int main()
{
student MyStudent;
MyStudent.output();
}
Does it compile? Does it run?
No. Then fix any errors you get and try again.
You then continue in this way
The problem with newbies is, that they always think that
programmers write a program in one big rush. They think
we sit down at the computer and are typing for hours, then
the compiler runs through the code, maybe one or two syntax
errors which are easily fixed and, hey, we have a working
program.
The truth is: nobody works that way.
Programmers work by implementing small pieces of the assignment
and testing those pieces. Only after one piece works, the next
piece gets implemented. This way we know, if a problem occours it
is most likely the last implemented piece which gives the problem.
You should work the same way. For now ignore seom details in the
assignment and concentrate on what you can implement. Use those
pieces to implement other pieces from the assignment until ...
well ... until the whole assignment is done.