wujekjajus Temat założony przez niniejszego użytkownika |
Kompilacja i implementacja Klasy » 2010-12-08 20:26:47 Napisać klasę o nazwie Magazyn która będzie przechowywała dane o nazwie, adresie, telefonie,faxie, numerze wewnętrznym identyfikujące dany magazyn. Niektóre dane mogą być modyfikowane tj. adres telefon i fax. Dokonać implementacji klasy.
#include <cstdlib> #include <iostream>
using namespace std;
int main( int argc, char * argv[] ) { class Magazyn { private: char nazwa[ 45 ]; int nr_wew[ 4 ]; public: char Adres_mag[ 30 ]; char Telefon_mag[ 30 ]; char Fax_mag[ 26 ]; Magazyn( char * n, int nr, char * a, char * t, char * f ) } { strcpy( nazwa, n ); nr_wew = nr; strcpy( Adres_mag, a ); strcpy( Telefon_mag, t ); strcpy( Fax_mag, f ); char * zwrocNazwa() { return nazwa; } int zwrocNumer() { return nr_wew; } } };
Proszę o poprawę błędu(ów) Dzięki |
|
ison |
» 2010-12-08 20:30:13 klasa w funkcji? poza tym klamry masz pomieszane całkiem #include <cstdlib> #include <iostream>
using namespace std;
class Magazyn { private: char nazwa[ 45 ]; int nr_wew; public: char Adres_mag[ 30 ]; char Telefon_mag[ 30 ]; char Fax_mag[ 26 ]; Magazyn( char * n, int nr, char * a, char * t, char * f ) { strcpy( nazwa, n ); nr_wew = nr; strcpy( Adres_mag, a ); strcpy( Telefon_mag, t ); strcpy( Fax_mag, f ); } char * zwrocNazwa() { return nazwa; } int zwrocNumer() { return nr_wew; } };
int main( int argc, char * argv[] ) { }
|
|
malan |
» 2010-12-08 21:11:14 Tak z ciekawości... Robisz to do pracy, czy na ocenę? |
|
Elaine |
» 2010-12-08 21:36:19 Tak, w końcu można definiować klasy wewnątrz funkcji (co prawda tu nie ma to sensu... ale cicho). |
|
wujekjajus Temat założony przez niniejszego użytkownika |
zaliczenie » 2010-12-08 22:59:30 na zaliczenie w szkole |
|
malan |
» 2010-12-09 15:32:51 Nie lepiej tak? class Store { public: Store(); Store( int id, const std::string & sAddress, const std::string & sFNumber, const std::string & sName, const std::string & sTelephoneNumber ); const std::string & GetAddress(); const std::string & GetFaxNumber(); int GetID(); const std::string & GetName(); const std::string & GetTelephoneNumber(); void SetAddress( const std::string & nAddress ); void SetFaxNumber( const std::string & nFax ); void SetID( int nID ); void SetName( const std::string & nName ); void SetTelephoneNumber( const std::string & nTelephoneNumber ); private: int innerIdentificationNumber; std::string address; std::string faxNumber; std::string name; std::string telephoneNumber; };
Store::Store() : innerIdentificationNumber( - 1 ) , address( "" ) , faxNumber( "" ) , name( "" ) , telephoneNumber( "" ) { }
Store::Store( int id, const std::string & sAddress, const std::string & sFNumber, const std::string & sName, const std::string & sTelephoneNumber ) : innerIdentificationNumber( id ) , address( sAddress ) , faxNumber( sFNumber ) , name( sName ) , telephoneNumber( sTelephoneNumber ) { }
const std::string & Store::GetAddress() { return address; }
const std::string & Store::GetFaxNumber() { return faxNumber; }
int Store::GetID() { return innerIdentificationNumber; }
const std::string & Store::GetName() { return name; }
const std::string & Store::GetTelephoneNumber() { return telephoneNumber; }
void Store::SetAddress( const std::string & nAddress ) { address = nAddress; }
void Store::SetFaxNumber( const std::string & nFax ) { faxNumber = nFax; }
void Store::SetID( int nID ) { innerIdentificationNumber = nID; }
void Store::SetName( const std::string & nName ) { name = nName; }
void Store::SetTelephoneNumber( const std::string & nTelephoneNumber ) { telephoneNumber = nTelephoneNumber; } |
|
waxx |
» 2010-12-09 17:58:49 Nie |
|
Elaine |
» 2010-12-09 19:10:54 ...odpowiedź uzasadnij. :P |
|
« 1 » 2 |