Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 11-22-07   #1 (permalink)
*cough* Stock *cough*
 
icyblizard's Avatar
 
intel nvidia

Join Date: Dec 2006
Location: Singapore
Posts: 46

Rep: 2 icyblizard Unknown
Unique Rep: 2
Trader Rating: 0
Exclamation Question about C++ inheritence

#ifndef PERSON_H
#define PERSON_H

class person
{
string name;
string NRIC;
int age;
public:
void GetName(string n);
void GetNRIC(string nric);
void GetAge(int a);
string ReturnName() const;
string ReturnNRIC() const;
int ReturnAge() const;
virtual void printName() const=0;
virtual void PrintNRIC() const=0;
virtual void printAge() const=0;

person(string n="person",string nric="S1234567Z",int a=100);
};

#include "person.h"
#ifndef STUDENT_H
#define STUDENT_H

class studentublic person
{
string AdminNo;
public:
void GetAdminNo(string a);
string ReturnAdminNo() const;
void printName() const;
void PrintNRIC() const;
void printAge() const;
void PrintAdminNo() const;

student(string n="student",string nric="S8954443C",int a=10,string admin="071234Z");
};
#endif

I want to make a database that can store 5 sets of data from either person class or student class, is that possible?
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz

System: Dell
CPU
P4 2.4GHz
Motherboard
not sure
Memory
Kingston 768 Mb DDR-333
Graphics Card
Geforce 4 Mx 400
Hard Drive
Hitachi 160 GB HDD
Sound Card
Creative Soundblaster 5.1
Power Supply
icute 420W
Case
stock
CPU cooling
stock
GPU cooling
none
OS
Wins XP
Monitor
not sure
icyblizard is offline   Reply With Quote
Old 11-22-07   #2 (permalink)
First Time Build
 
intel nvidia

Join Date: Nov 2007
Posts: 36

Rep: 6 brightemo Unknown
Unique Rep: 2
Trader Rating: 0
Default

Define database in this case?
__________________
System: On Its Way
CPU
Q6600 G0
Motherboard
ASUS P5K-E/WIFI-AP
Memory
4 x 1GB Corsair XMS2 6400 C4
Graphics Card
Palit 8800GT Sonic 512MB
Hard Drive
Samsung SpinPoint HD501LJ 500GB
Power Supply
Be Quiet DarkPower Pro Modular 530W
Case
Aplus Twin Engine Silver
CPU cooling
Zalman CNPS 9700 LED
OS
Vista Ultimate 64-Bit
Monitor
22" Philips 220WS8FS TFT
brightemo is offline   Reply With Quote
Old 11-22-07   #3 (permalink)
Programmer
 
kdbolt70's Avatar
 
intel ati

Join Date: May 2007
Location: Walled Lake, MI
Posts: 1,119

Rep: 127 kdbolt70 is acknowledged by manykdbolt70 is acknowledged by many
Unique Rep: 92
Folding Team Rank: 284
Trader Rating: 1
Default

I'm not quite sure what you mean by database, but I'm assuming you want to store objects, or pointer to objects to both people and students. You could do this by making all objects of type person. (I don't know if you know all this, so I'll go through it a little bit anyways). You could do something like:

Code:
Person *studentPtr = new Student("John", "nric12345", 15, "123456789");
Person *personPtr = new Person();

add_to_database(studentPtr);
add_to_database(personPtr);
This basically outlines the fact that a subclass can be initilized in a base class pointer. This then can be handed around like a base class without really knowing it is an inherited class type. The problem comes whenever you want to access a member function from a student pointer. In the example above, your studentPtr will be thought of as a person, and will therefore have no idea what do do when you do:

Code:
studentPtr->PrintAdminNo();
this is because a person object has no access to any subclass functions not defined in the base class. To solve this you either need a fat interface (i.e virtualize all the methods in the subclass in the baseclass) or cast the pointer to a student pointer if you KNOW it is a student. You also could store them separately (some as people and some as students) but this kinda defeats the purpose.

In terms of making a database that can store it... Basically you'll need to store pointers to objects of type person, and load it with ptrs to persons and students. Other than that I don't know what you mean by database.
__________________

~M Hail to the Victors M~

System: It's about time!
CPU
Q6600 G0 @3.3Ghz
Motherboard
Gigabyte P35-DS3L
Memory
2Gb Ballistix DDR2 800 @915Mhz
Graphics Card
Sapphire 2900Pro Flashed to XT
Hard Drive
Seagate Barracuda 320Gb
Sound Card
Onboard
Power Supply
Corsair HX 620W
Case
CM 690
CPU cooling
Tuniq Tower 120
GPU cooling
stock
OS
Vista Business and VMWare Ubuntu
Monitor
Acer AL2223W 22"
kdbolt70 is offline I fold for Overclock.net   Reply With Quote
Old 11-23-07   #4 (permalink)
*cough* Stock *cough*
 
icyblizard's Avatar
 
intel nvidia

Join Date: Dec 2006
Location: Singapore
Posts: 46

Rep: 2 icyblizard Unknown
Unique Rep: 2
Trader Rating: 0
Default

Woot! Problem solved, the correct way was to do it using polymorphism (pointers to class), like kdbolt70 had said
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz

System: Dell
CPU
P4 2.4GHz
Motherboard
not sure
Memory
Kingston 768 Mb DDR-333
Graphics Card
Geforce 4 Mx 400
Hard Drive
Hitachi 160 GB HDD
Sound Card
Creative Soundblaster 5.1
Power Supply
icute 420W
Case
stock
CPU cooling
stock
GPU cooling
none
OS
Wins XP
Monitor
not sure
icyblizard is offline   Reply With Quote
Old 11-23-07   #5 (permalink)
PC Gamer
 
crazydj's Avatar
 
intel nvidia

Join Date: Apr 2007
Posts: 549

Rep: 13 crazydj Unknown
Unique Rep: 11
Hardware Reviews: 1
Trader Rating: 0
Default

icyblizard, are you taking A-Levels computing?
__________________
I am 38% addicted to Counterstrike. What about you?

System: My Core 2 Duo Rig
CPU
Intel Core 2 Duo E6600
Motherboard
Asus P5N-E SLI 650i
Memory
PC6400/800 Crucial DDR2 1GB CL5 x2
Graphics Card
XFX NVIDIA GeForce 8800 GTS 320MB DDR3
Hard Drive
Segate 320GB 16MB 5 Years SATA2
Sound Card
Integrated
Power Supply
Corsair HX520W Modular PSU
Case
CoolerMaster Centurion 5 w/Side Window (Silver)
CPU cooling
Thermaltake Ruby Orb
GPU cooling
Stock
OS
Windows Vista Home Premium 32 Bit
crazydj is offline   Reply With Quote
Old 11-23-07   #6 (permalink)
*cough* Stock *cough*
 
icyblizard's Avatar
 
intel nvidia

Join Date: Dec 2006
Location: Singapore
Posts: 46

Rep: 2 icyblizard Unknown
Unique Rep: 2
Trader Rating: 0
Default

No, im taking a diploma in Digital Entertainment Technology. It involves alot of programming for either CG or games. 3 of my current subjects are C++ related
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz

System: Dell
CPU
P4 2.4GHz
Motherboard
not sure
Memory
Kingston 768 Mb DDR-333
Graphics Card
Geforce 4 Mx 400
Hard Drive
Hitachi 160 GB HDD
Sound Card
Creative Soundblaster 5.1
Power Supply
icute 420W
Case
stock
CPU cooling
stock
GPU cooling
none
OS
Wins XP
Monitor
not sure
icyblizard is offline   Reply With Quote
Old 11-24-07   #7 (permalink)
PC Gamer
 
crazydj's Avatar
 
intel nvidia

Join Date: Apr 2007
Posts: 549

Rep: 13 crazydj Unknown
Unique Rep: 11
Hardware Reviews: 1
Trader Rating: 0
Default

I see. When i was doing my A-Levels practical using C++, i had like only 2 hours of sleep everyday for 3 and and half months! Anyway, just keep on practicing man! Good luck!
__________________
I am 38% addicted to Counterstrike. What about you?

System: My Core 2 Duo Rig
CPU
Intel Core 2 Duo E6600
Motherboard
Asus P5N-E SLI 650i
Memory
PC6400/800 Crucial DDR2 1GB CL5 x2
Graphics Card
XFX NVIDIA GeForce 8800 GTS 320MB DDR3
Hard Drive
Segate 320GB 16MB 5 Years SATA2
Sound Card
Integrated
Power Supply
Corsair HX520W Modular PSU
Case
CoolerMaster Centurion 5 w/Side Window (Silver)
CPU cooling
Thermaltake Ruby Orb
GPU cooling
Stock
OS
Windows Vista Home Premium 32 Bit
crazydj is offline   Reply With Quote
Old 11-24-07   #8 (permalink)
*cough* Stock *cough*
 
icyblizard's Avatar
 
intel nvidia

Join Date: Dec 2006
Location: Singapore
Posts: 46

Rep: 2 icyblizard Unknown
Unique Rep: 2
Trader Rating: 0
Default

Ooh, thanks
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz

System: Dell
CPU
P4 2.4GHz
Motherboard
not sure
Memory
Kingston 768 Mb DDR-333
Graphics Card
Geforce 4 Mx 400
Hard Drive
Hitachi 160 GB HDD
Sound Card
Creative Soundblaster 5.1
Power Supply
icute 420W
Case
stock
CPU cooling
stock
GPU cooling
none
OS
Wins XP
Monitor
not sure
icyblizard is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:49 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.31765 seconds with 8 queries