473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Design Student Class

Hi,

I would like to design a Student Class containing the private members namely Char *Name,int Age and Char Sex.

The constructor of the class need to be passed with only one String argument..

The String passed is in the format like

Student S("David 18 M") each is separated by a single space.
Now the private members of the class need to be filled with corresponding values....

Please let me know how to implement this scenario?

I have used find method of String class to find the index at which space is located but unable to fill it correctly.
Sep 22 '06 #1
2 3179
dush
27
Hi

Here is code for your student class:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. class S {
  7.  
  8.   char _name[32];
  9.   int _age;
  10.   char _sex;
  11.  
  12.   public:
  13.  
  14.   S(char* str) {
  15.     stringstream s(str);
  16.     s >> _name >> _age >> _sex;        
  17.   }        
  18.  
  19.   void print(void) const
  20.   {
  21.     cout << "Student name: " << _name << endl;
  22.     cout << "Student age:  " << _age << endl;
  23.     cout << "Student sex:  " << _sex << endl;
  24.   }
  25. };
  26.  
  27. int main(){
  28.  
  29.   S student("David 18 M");    
  30.   student.print();    
  31.   return 0;
  32. }
Sep 22 '06 #2
Hi Dush,

Thankyou for the Quick reply.


Hi

Here is code for your student class:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. class S {
  7.  
  8.   char _name[32];
  9.   int _age;
  10.   char _sex;
  11.  
  12.   public:
  13.  
  14.   S(char* str) {
  15.     stringstream s(str);
  16.     s >> _name >> _age >> _sex;        
  17.   }        
  18.  
  19.   void print(void) const
  20.   {
  21.     cout << "Student name: " << _name << endl;
  22.     cout << "Student age:  " << _age << endl;
  23.     cout << "Student sex:  " << _sex << endl;
  24.   }
  25. };
  26.  
  27. int main(){
  28.  
  29.   S student("David 18 M");    
  30.   student.print();    
  31.   return 0;
  32. }
Sep 25 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tony Johansson | last post by:
Hello Experts!! Here we use multiple inheritance from two classes.We have a class named Person at the very top and below this class we have a Student class and an Employee class at the same...
1
by: Corinne | last post by:
I have a database that contains the details of pupils in a school. What I would like to do may not be possible but I thought I would ask anyway. Each year the pupils move to a different class,...
15
by: kimi | last post by:
I have just started working on a project that is partially complete. It is an application that is using access to store test results. The test results are being stored in two Access 2000 databases....
2
by: cm500 | last post by:
I'm very new to databases so bear with me. What I need is a way to track the training for the employees at my firm. I have 40 classes that I will be teaching on various subjects and various...
5
by: William Wisnieski | last post by:
Hello Everyone, I'm really stuck on how to design this application, so I thought I'd see if anyone had any general ideas on how to proceed. I'd say I'm an intermediate level Access developer. ...
6
by: John Lee | last post by:
Hi, I was trying to find an elegant way of implementing/modelling the following scenario: student, borrower, reference and cosigner are all human beings - we would think to create a person...
3
by: shahram.shirazi | last post by:
Hi guys, I was wondering if someone could help me a bit here. Im trying to desing an electronic register system for a school. In terms of the table design, I obviously need a Student Details...
11
by: xxbabysue123xx | last post by:
Heres the problem: Create a class Student with instance data name, studentNumber, class (where class is a String containing one of the following: “Freshman”, “Sophomore”, “Junior”, “Senior”. ...
2
by: thecheyenne | last post by:
Hi and good evening / good morning (depending on your location on this planet) Despite my limited - o.k, non-existing - knowledge of vba, I'd like to design a database to help with the admin of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.