Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyClassMethod
//g++ 7.4.0 //cppPyClassMethod //this code is created by Rezaul Hoque on January 24,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; //PythonClassMethod program(created on December 09,2021) looks like this: /************************** class Book: title= 'No Title' author= 'No author' genre= 'No genre' @classmethod def genBook(cls,title,genre): return cls(title,genre) @staticmethod def banner(): print("Python Class Method") print("December 09,2021") @staticmethod def pattern(): print("##############") book1=Book() book1='Kim','Rudyard Kipling','Adventure' book2=Book() book2='Sonar Kella','Detective Thriller' Book.pattern() Book.banner() print(book1) print(book2) Book.pattern() ********************/ #include <iostream> #include <string> class Book{ private: std::string title, author, genre; public: Book(){} Book(std::string t,std::string a,std::string g){title=t; author=a; genre=g;} Book(Book& c){title=c.title;author=c.author;genre=c.genre;} ~Book(){} static void banner(){std::cout<<"C++ equivalent of Python class method.\n"; std::cout<<"January 24,2022\n";} static void pattern(){std::cout<<"\n##############\n";} virtual std::string getT() const { return title;} virtual std::string getA() const { return author;} virtual std::string getG() const { return genre;} }; int main() { Book b1("Kim","Rudyard Kipling","Adventure"); Book b2("Sonar Kella","Satyajit Ray","Thriller"); Book::pattern(); Book::banner(); std::cout<<b1.getT(); std::cout<<"\t"; std::cout<<b1.getA(); std::cout<<"\t"; std::cout<<b1.getG(); std::cout<<"\n"; std::cout<<b2.getT(); std::cout<<"\t"; std::cout<<b2.getA(); std::cout<<"\t"; std::cout<<b2.getG(); Book::pattern(); return 0; }
run
|
edit
|
history
|
help
0
MeanSDVar
AVL - ith element
Shuffle algorithm
CyclicExpression Checker
TwoMax
idfc
HeapSort
Find value in sorted matrix
star print1
CutRod