Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyClass
//g++ 7.4.0 //cppPyClass:C++ equivalent of PyClass program //this code is created by Rezaul Hoque on January 26,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> //The Python code for PyClass(created on December 08,2021)goes like this: /****** from enum import Enum class Weath(Enum): A='GOOD' B='BAD' C='UGLY' class WeDay: day='Today' date='December 08,2021' sun='sunny' @staticmethod def pattern(): print("~~~~~~~~~~~~~~~~~~") print("~~~~~~~~~~~~~~~~~~") @staticmethod def banner(self): print("Python class example ") print(self.date) def DescDay(self): print(self.day," is a ") print(repr(Weath.A)) print(" day & ",self.sun) print (" It's time to take a walk. ") Weather = WeDay() Weather.day='Tuesday' Weather.pattern() Weather.banner(Weather) Weather.DescDay() Weather.pattern() *****/ // //above code in C++ looks like this: enum Weath {A,B,C}; std::string w[C+1]={"Good","Bad","Ugly"}; class WeDay{ private: std::string day,date,sun; public: WeDay(){} WeDay(std::string a,std::string b,std::string c){ day=a;date=b;sun=c;} WeDay(WeDay& w){ day=w.day;date=w.date;sun=w.sun;} ~WeDay(){} virtual std::string getDy() const { return day;} virtual std::string getDt() const { return date;} virtual std::string getS() const { return sun;} static void pattern() { std::cout<<"\n~~~~~~~~~~~~~~~~~~~\n"; std::cout<<"~~~~~~~~~~~~~~~~~~~\n"; } void banner() { std::cout<<" C++ equivalent of Python class example: \n"; std::cout<<this->getDt(); std::cout<<"\n"; } void descDay() { std::cout<<this->getDy()<<" is a "<<w[A]; std::cout<<" day & "<<this->getS()<<"\n"; std::cout<<" It's time to take a walk."; } }; int main() { WeDay a("Today","January 26,2022","sunny"); WeDay::pattern(); a.banner(); a.descDay(); WeDay::pattern(); return 0; }
run
|
edit
|
history
|
help
0
pure virtual function with non-fixed number of parameters
MyStack
SD
Two-phase sample with GCC
DailyGroceryHisto
triangle_ isosceles
A+B ორობით სისტემაში
Web Browser History - LIST
POI
Using C's sprinf() Function to Format Output String