Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyClassInit
//g++ 7.4.0 //cppPyClassInit: C++ equivalent of PyClassInit program //this code is created by Rezaul Hoque on February 07,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> /****** PyClassInit program (created on December 10,2021) was like this class Book: price = 200 #Class attribute def __init__(self, title, author, genre): self.title = title #instance attribute self.author = author self.genre = genre book1 = Book("Sonar Kella", "Stayajit Ray", "Adventure") book2 = Book("Kim", " Rudyard Kipling", "Adventure") print(book1.title, book1.author,book1.genre,book1.price) book2.price= 260 print(book2.title, book2.author, book2.genre,book2.price) *****/ //C++ code for above program: class Book{ private: static int price; 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 PyClassInit program.\n"; std::cout<<"February 07,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;} static int getP() { return price;} void setP(int a){ price =a;} }; int Book::price =200; 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<<"\t"; std::cout<<b1.getP(); std::cout<<"\n"; b2.setP(250); std::cout<<b2.getT(); std::cout<<"\t"; std::cout<<b2.getA(); std::cout<<"\t"; std::cout<<b2.getG(); std::cout<<"\t"; std::cout<<b2.getP(); Book::pattern(); return 0; }
run
|
edit
|
history
|
help
0
Test 12(2021)
Sorting sort function stl in c++
fundamental type sizes
template inhertinace
SOS DP
MinCostKStops_BFS
PATRA_Class_test
CS 201
merge without extra space Gap method ALgorithm
Hashing