+ 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?
16 ответов
+ 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();.........*/
+ 4
Secret Superstar i mean post your tried code.. then only others understand how you are trying..?
What errors if any?
+ 3
It is recommended to first try yourself..
If not get solved, then post your try here..
+ 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++.*/
+ 3
Use a static variable as a counter.
+ 2
Yes I tried myself than only I posted
+ 2
Yes you are right
+ 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()
}
+ 2
Bhai go through it
+ 2
Dhanyavad ❤️ Bhai
+ 2
Vese. Me galti kaha kar rha tha
+ 2
Dhanyavad ❤️Jayakrishna🇮🇳 ji
+ 2
Dhanyavad ❤️rupali ji
+ 2
Yup
+ 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.
0
هلااا