Solved

c++program

Posted on 2000-03-22
3
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

696 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