Creating classes

Program Objective:
Create class named quark which will store the name (up, down, charm, strange, top or bottom), charge (+2/3, -1/3, +2/3, -1/3, +2/3, -1/3 e) and mass (1.5-3.3, 3.5-6.0, 1,160-1,340, 70-130, 169,100-173,300 or 4,130-4,370 MeV/c^2). The quark class should be able to set and get each of the member data. The set functions should validate input values.

Create a program that creates an array of 5 quark objects, sets their values randomly and display the quarks sorted by their mass.

Include documentation for your class definition and implementation.

Member Function Names:

Thats my assignment. This is what i have written for the header but i'm not sure if its correct. Not sure if the format is correct and not sure when to use const.

class Quark {
Quark(string Flavor, float Mass, double Charge);
float setmass()const;
string getName()const;
double getCharge()const;
float getMass()const;


string Flavor;
float Mass;
double Charge;

thanks in advance guys
A few things:

1) const on a function tells the compiler the function does not change any members of the class. A setter is intended to change the value, so const on setmass is not appropriate.

2) setter functions take a value as an argument, so setmass should be:
void setmass(float m);

Setters don't generally return a value, although there is no reason they can't.

3) Assignment says to provide a setter and getter for each variable. I don't see setters for Flavor or Charge.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.

Topic archived. No new replies allowed.