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; }

23rd Aug 2020, 5:12 PM
ihsanullah Ihsan
ihsanullah Ihsan - avatar
6 Respuestas
+ 4
What is x here can u tell
23rd Aug 2020, 5:32 PM
💫As💫
+ 3
You can add another argument to the 'showinfo' telling the index of the object!
23rd Aug 2020, 5:15 PM
Namit Jain
Namit Jain - avatar
+ 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.
23rd Aug 2020, 5:25 PM
💫As💫
0
Without another argument
23rd Aug 2020, 5:16 PM
ihsanullah Ihsan
ihsanullah Ihsan - avatar
0
It's ok but in the place of x what I will do to show me the current object number
23rd Aug 2020, 5:29 PM
ihsanullah Ihsan
ihsanullah Ihsan - avatar
23rd Aug 2020, 5:46 PM
ihsanullah Ihsan
ihsanullah Ihsan - avatar