+ 5

You have to create a class and declare a function inside the class , using c++ language

You have to create a class and declare a function inside the class , After that When we will call that function from outside the class first time it should show Hello 1 Next time call it should show Hello 2 And so on When we will call 6th time it should display limit over But we need to call the function by min 3 different objects Anyone can this C++ Problem?

17th Sep 2020, 5:21 PM
Secret Superstar
Secret Superstar - avatar
16 Answers
+ 2
//Corrected code: #include <iostream> using namespace std; //#include <conio.h> class student { static int count; public: student() { if(count<=5){ cout<<"Hello"<<count<<endl; ++count; } else cout <<"your limit execcded\n"; } }; int student::count=1; int main() { //clrscr(); student s1,s2,s3,s4,s5,s6,s7; //getch() } /* You should use, std::cout or add using namespace std at top. conio.h is deprecated nonstandard header don't work here.. Also clrscr().., windows function, not work. Same for getch(),, use instead getchar() if you need... You are using a constructor here(also function but special function not normal function), not function... In description, you said need function to call.. If you need in that way exactly, try change name of student() to any.. Like void std() {..} Then call s1.std();s2.std(); s2.std(); s3.std();.........*/
17th Sep 2020, 7:02 PM
Jayakrishna 🇮🇳
+ 4
Secret Superstar i mean post your tried code.. then only others understand how you are trying..? What errors if any?
17th Sep 2020, 5:29 PM
Jayakrishna 🇮🇳
+ 3
It is recommended to first try yourself.. If not get solved, then post your try here..
17th Sep 2020, 5:26 PM
Jayakrishna 🇮🇳
+ 3
//code #include <iostream> using namespace std; class student { static int count; public: student() { if(count<=5){ cout<<"Hello"<<count<<endl; ++count; } else cout <<"your limit execcded"; } }; int student::count=1; int main() { student s1,s2,s3,s4,s5; return 0; } /* you have no need to use clrscr () function or getch () function. Screen will be automatically clear, I think you are using turbo c++.*/
17th Sep 2020, 7:05 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 3
Use a static variable as a counter.
17th Sep 2020, 10:25 PM
Sonic
Sonic - avatar
+ 2
Yes I tried myself than only I posted
17th Sep 2020, 5:27 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Yes you are right
17th Sep 2020, 5:30 PM
Secret Superstar
Secret Superstar - avatar
+ 2
#include <iostream> #include <conio.h> class student { static int count; public: student() { if(count<=5){ cout<<"Hello"<<count<<endl; ++count; } else cout <<"your limit execcded"; } }; int student::count=1; void main() {clrscr(); student s1,s2,s3,s4,s5; getch() }
17th Sep 2020, 6:53 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Bhai go through it
17th Sep 2020, 6:59 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Dhanyavad ❤️ Bhai
17th Sep 2020, 7:04 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Vese. Me galti kaha kar rha tha
17th Sep 2020, 7:05 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Dhanyavad ❤️Jayakrishna🇮🇳 ji
17th Sep 2020, 7:07 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Dhanyavad ❤️rupali ji
17th Sep 2020, 7:07 PM
Secret Superstar
Secret Superstar - avatar
+ 2
Yup
17th Sep 2020, 7:10 PM
Secret Superstar
Secret Superstar - avatar
+ 1
Tumne cout ko use kiya, pr using namespace std or std:: cout ko add nhi kiya, uske tumne getch function ka use kiya, or clrscr inki need turbo c++ pe hoti hai, modern compiler pe nhi. Hope you understood.
17th Sep 2020, 7:09 PM
Rupali Haldiya
Rupali Haldiya - avatar
0
هلااا
5th Oct 2020, 12:41 PM
ابوبكر عبداللطيف
ابوبكر عبداللطيف - avatar