Solved

c++program

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

706 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

20 Experts available now in Live!

Get 1:1 Help Now