Solved

c++program

Posted on 2000-03-22
3
486 Views
Last Modified: 2010-04-02
Can u help me with the source code with the following problem. thanks in advance

Define a class that represents a student. Its data include a student's ID number, last name, first name, and credit hours completed. its member function include one that assigns value to a student object and one that displays the values in a student object
0
Comment
Question by:greaser1
3 Comments
 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2648096
Is it your homework? If so you cann't find the solution here.

Andrew
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2648323
again as i said
i can write it for you
'cause in EE we can't answer a homework questions

but i"ll help you a little

first about the class you should
decid if your which of the data members should be private and which public <the data mostlly is private if not all of it>

not the class structure:

class  classname{
......//data members in private
......//private funcs if there is some
public:
......//C'tor's you don't have to use them
......//data if there is some usually you
    //put the data in the private
......//the public func
......//D'tor's you don't have to use them
};

about the methods (class functions) :
you should make input and output methods
and for that it will better if you"ll use operators like the operator << and
>> 

it the basics for you



0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 2652863
>Define a class that represents a student.

class Student {
  ...body goes here...
};

>Its data include a student's ID number, last name, first name, and credit hours completed.

Unless you havea good reason otherwise, data memebers should be private.  The usual convention is to list all private members toward the end of a class definition (with 'private:' in front of them).

class Student {
public:
  ...public memeber functions go here...
private:
  long myIdNumber; // assuming it is numeric
  string myLastName;
  ...etc for other member variables...
};

>its member function include one that assigns value to a student object

there are five main ways to assign values to a student object.  The first is to initialise to default values via a default constructor.  The second is by constructing from another existing student object (a copy constructor).  The third is using the '=' operator to assigning an new value to an object.  The fourth is a constructor that passes particular initial values.  The last is functions that directly set your memebre data.

class Student {
public:
  Student(); // default constructor
  Student(const Student& s); // copy constructor
  Student& operator=(const Student& s); // assignment
  Student(long anIdNumber, string aFirstName,...); // constructor
  void SetFirstName (string aFirstName); // set name
  ...etc for other member functions...
private:
  long myIdNumber; // assuming it is numeric
  string myLastName;
  ...etc for other member variables...
};

>and one that displays the values in a student object

by display I assume you means write it out to a stream.  best is to write your own 'insertion' operator ('<<').  This needs to be a friend function (ie. it cannot be a member because the LHS of << is the stream).

class Student {
public:
  Student(); // default constructor
  Student(const Student& s); // copy constructor
  Student& operator=(const Student& s); // assignment
  Student(long anIdNumber, string aFirstName,...);
  void SetFirstName (string aFirstName); // set name
  friend ostream& operator<< ( ostream& os, const Student& s );
  ...etc for other member functions...
private:
  long myIdNumber; // assuming it is numeric
  string myLastName;
  ...etc for other member variables...
};

That would seem to be the basic framework for the class declaration.

Now you just need to fill in the bodies for the memeber functions and define the rest of the member variables.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question