Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ClassQuiz2
//g++ 7.4.0 ///////////////////////////////////////////////////////////////////////////// //ClassQuiz2 //quiz() code credit goes to thecleverprogrammer and SmallLion/Mr Unity Buddy of github //rest of the code created by Rezaul Hoque on August 02,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 <sstream> #include <string> //stream manipulator std::ostream& l(std::ostream& os) { return (os<<"\n"); } namespace Pat{ void fill(char c) { std::cout.width(40); std::cout.fill(c); std::cout<<l; } } namespace Quiz{ class Quiz{ public: void welcome (){ std::stringstream s("Welcome to the quiz!You have 3 questions.Each right answer will bring you 10."); std::cout<<s.str()<<l; Pat::fill('~'); Pat::fill('~'); } void quiz(){ std::string RightAns[]={"Everest","Amazon","Bering"}; int score=0; std::string ans; std::cout<<"What is the name of the highest peak of the world?\n"; std::stringstream o1("Alps,Mt. Everest,Kilimanjaro"); std::cout<<o1.str()<<l; std::cin>>ans; if (ans==RightAns[0]) { std::cout<<" Right you are!\n"; ++score;} else {std::cout<<"That's not right\n";} std::cout<<"Which one is the longest river on earth?\n"; std::stringstream o2("Ganges, Mississippi,Amazon"); std::cout<<o2.str()<<l; std::cin>>ans; if(ans==RightAns[1]){ std::cout<<" Right you are!\n"; ++score; } else {std::cout<<"That's not right.\n";} std::cout<<"Which strait lies between USA and Russia?\n"; std::stringstream o3("Palk,Hormuz,Bering"); std::cout<<o3.str()<<l; std::cin>>ans; if(ans==RightAns[2]) { std::cout<<" Right you are!\n"; ++score;} else {std::cout<<"That's not right.\n";} int m; m=score*10; std::cout<<"Your score is "<<m; if(m<30) std::cout<<". Try better next time!\n"; else if(m==30) std::cout<<". Awesome!\n"; } }; } int main() { Pat::fill('@'); Pat::fill('@'); Quiz::Quiz q; q.welcome(); q.quiz(); Pat::fill('@'); Pat::fill('@'); return 0; }
run
|
edit
|
history
|
help
0
Test 13(2020)
Stream5
Karibu
Dar
static_cast makes a copy
doubly
Merge problem
Triplet sum in array
Org
cccc