Solved

c++program

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 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.

617 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