Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyBatScoreSOLID
//g++ 7.4.0 //cppPyBatScoreSOLID //this code is created by Rezaul Hoque on August 20,2022; update : 18:42 ,August 21,2022 //contact: jewelmrh@yahoo.com; Dhaka, Bangladesh,https://rezaulhoque.wordpress.com;https:hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <string> #include <vector> class Person{ std::string first, last; public: Person (){} Person(std::string s,std::string b){this->first=s;this->last=b;} std::string getF(){ return first;} std::string getL(){return last;} void Print(){ std::cout<<first<<" "<<last<<"\n";} }; class Batter: public Person{ int match,run; public: Batter(){} Batter(std::string first, std::string last,int m,int r): Person (first, last),match(m),run(r){} ~Batter(){} int getM(){return match;} int getR(){return run;} float Mavg(){ return run/match;} }; class PerAbsTran{ float res; int total; public: PerAbsTran(){} PerAbsTran(float r,int t){res=r;total=t;} float getRes(){return res;} int getTot(){return total;} virtual float convert()=0; }; class Abs2Per: public PerAbsTran{ public: Abs2Per(float res,int total):PerAbsTran(res,total){} float convert(){ return getRes()/getTot()*100;} }; class Per2Abs : public PerAbsTran{ public: Per2Abs(float res,int total):PerAbsTran(res,total){} float convert(){ return getRes()/100*getTot();}; }; int main() { std::vector<Batter> det; det.push_back(Batter("hh","cc",5,182)); det.push_back(Batter("tt","nn",6,270)); det.push_back(Batter("yy"," mm",8,350)); std::cout<<"name(first,last) match run avg\n"; std::vector<Batter>::iterator it; for(it=det.begin(); it!=det.end();it++){ std::cout<<it->getF()<<" "<<it->getL()<<" "<<it->getM()<<" "<<it->getR()<<" "<<it->getR()/it->getM()<<"\n"; } int totm=0; int totr=0; for(it=det.begin(); it!=det.end();it++){ totm += it->getM(); totr += it->getR(); } std::cout<<" Total match :"<<totm<<"\n"; std::cout<<" Total Run:"<<totr<<"\n"; Abs2Per abs(182,802); std::cout<<"First player scored "<<abs.convert()<<" % of total runs.\n"; return 0; }
run
|
edit
|
history
|
help
0
char
Tray
PrintShapePointer
cpp ex 3 - solution
Age
PriQHotel
pattern
data locality - fast example
Vector
temporaries and move constructor