Solved

c++program

Posted on 2000-03-22
3
480 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now