Tuesday, July 14, 2009

Help !!! Problems with Object Orinted Programming in C++?

Im suppose to create a class to specify the data of students in a university with the following data members:





Data members Data Type


• Student name string


• Student id integer


• Fees float


• Course code integer


• IT marks float


• Mathematics Marks float


• Social Studies float





Write member functions for the following member functions for the data members


1. Initialize the values for the data members using the constructor


2. Calculate the average marks of a student


3. To register a student for a particular course. (Students must pay at least half of the specified fees in order to register for a course.)


4. To graduate from the university a student must have an average of at least 50%.


5. Print the above data members and average on the screen


The average function must be declared outside of the class.


Create an object for the students and call the appropriate member functions

Help !!! Problems with Object Orinted Programming in C++?
I got your private message notifying me of the update to your question. I'm not going to be able to effectively help you. It looks like there is a lot you don't understand about C++ and it's late in the semester so you might be out of luck. It would be better to find someone locally to help you. Here are some observations as I look at your code:





* You're not initializing the data members in the constructor.


* There's no rhyme nor reason to what is public and what is private.


* There are no member functions such as might be used to access the private data.


* The line "universityStudents::fees;" doesn't do anything and I believe it's syntactically incorrect. If the member variable fees was static, it would be referencing that member.


* You're trying to load values into member variables but you don't have an instance of the class to work with so you're going to get errors saying that the variable fees is undefined.


* The range test for fees misspells fees (i.e. "fee") and includes a dollar sign and a space in the value. Both fees and fee will be reported as undefined (the first since you have no instance of the class and the second since it's misspelled). The dollar sign and the space are going to also cause errors.


* The line "universityStudents::avg;" doesn't do anything and is probably an error.


* The attempts to load student marks into Informationtechnology, Mathematics, and Socialstudies will fail as those variables are undefined. Even if you had an instance of the class and tried to load the values using syntax like pStudent-%26gt;Mathematics it will fail because for some inexplicable reason Mathematics is a private member of the class.


* You have the avge() function defined inside main(). This might be legal in C++ but I've never tried it because it was illegal in C. Looks like you either don't have a clue or you're a former Pascal programmer. There are no local functions in C++ AFAIK.





In short, there's pretty much nothing about your code that meets the assignment (which itself is very vague and in my opinion is impossible to complete with the information you've provided).





You need to either pay closer attention in class, get some local help, or consider another major.
Reply:You should go down your own list and do it. You have it piece meal. You are not getting the students name, registering them properly if ((fee/2)==whatever), there are no methods/functions in your object....





so, do one thing at a time.


Get the students name, get the grades and print them. If you can do that, cool.


Then do the fee. Make print outs to make sure you are doing it right,





then go from there,,,,

flower garden

No comments:

Post a Comment