0
How can I show that?this is the first?second?third?object in showinfo() function ?
#include<iostream> Static int count_obj=0; class student { public: string name; int id; student(int I,string n) { count_obj++; id=i; name=n; } void showinfo() { cout<<"total object is "<<count_obj<<endl; cout<<" name is :"<<name<<endl <<" id is :"<<id<<endl; cout<<"this is "<<x<<"th object"<<endl; } }; Int main() { student stu1(10,"sami"): student stu2(20,"farid"); student stu3(30,"ihsan"); student stu4(40,"ismail"); student stu5(50,"farhad"); stu3.showinfo(); stu5.showinfo(); return 0; }
6 Respuestas
+ 4
What is x here can u tell
+ 3
You can add another argument to the 'showinfo' telling the index of the object!
+ 3
In your program have some syntex errors and your two variables id =i and variable x are undefined and in main function student std1 (10,"sami"); here put colon in place of semicolon.
0
Without another argument
0
It's ok but in the place of x what I will do to show me the current object number