Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
NameAdTel
//g++ 7.4.0 //Name Address Telephone: overloading insertion and extract operators to get the desired telephone number format [ country (code) exchange-number ] //created by Rezaul Hoque on January 3,2021 //contact at jewelmrh@yahoo.com #include <iostream> #include <string> using namespace std; class Tel{ friend istream& operator>>(istream&, Tel&); friend ostream& operator<<(ostream&, const Tel&); public: Tel (int c=0, int cod=0, int ex=0, int num=0) : country (c),code(cod),exchange (ex), number (num) {} void setTel(int c, int cod, int ex,int num){ country = c; code= cod; exchange=ex; number =num;} private: int country, code, exchange, number; }; istream& operator>>(istream& w, Tel& t) { w>>t.country >>t.code>>t.exchange>>t.number; return w; } ostream& operator<<(ostream& p,const Tel& t) { static string cName[8]= { " ", "Nulpart","Bizaristan","Neverland", "Negada","Utopistates","Holow Kingdom","Absurdistan"}; p<<cName[t.country ]<<' '<<'('<<t.code<<')'<<t.exchange <<'-'<<t.number; return p; } class Indiv: public Tel{ private: string name, address; Tel helo; public: Indiv(){} Indiv(string n, string ad){ name =n; address = ad;} Indiv(Indiv& c){ name = c.name; address =c.address;} ~Indiv(){} virtual void setHelo(int c, int cod, int ex, int num){ helo.setTel(c,cod,ex,num);} virtual Tel getHelo() const { return helo;} virtual string getName() const { return name;} virtual string getAd() const {return address;} }; int main () { const int max=3; Indiv * Indi; Indi = new Indiv[max]; Indi[0]={"Mr A","123 nowhere"}; Indi[1]={"Mr B","321 nowhere"}; Indi[2]={"Mrs C","222 nowhere"}; Indi[0].setHelo(1,202,123,4321); Indi[1].setHelo(2,101,321,12345); Indi[2].setHelo(3,303,321,2324); cout<<"Name Address Telephone:\n"; for (int i=0; i<max; i++) { cout<<"\n"; cout<<Indi[i].getName()<<"\t"; cout<<Indi[i].getAd()<<"\t"; cout<<Indi[i].getHelo()<<"\t"; cout <<endl; } delete [] Indi; return 0; }
run
|
edit
|
history
|
help
0
Gauss v1.1
Pierwiastkowanie
Dar
PRIx64 on gcc
Tubee c++
NamespaceOverload
2018JanSilv2
Prime_Number_Cpp
poprawione-obcinanie-koncowek.
ewfgrthry