计数在c++中创建的对象的数量
Count number of objects created in C++
需要计数。在setval中创建的对象。请帮助。源代码:https://www.dropbox.com/s/z6igpioidhov9oo/static.cpp
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
static int count;
protected:
char name[20];
char course[20];
int roll;
float fees;
public:
student()
{
}
void setval()
{
count++;
cout<<"nEnter the name : ";
cin>>name;
/*cout<<"nEnter the course : ";
cin>>course;
cout<<"nEnter the roll : ";
cin>>roll;
*/cout<<"nEnter the fees : ";
cin>>fees;
}
friend float calfeespaid(student);
void showval()
{
cout<<"nName = "<<name;
//cout<<"nCourse = "<<course;
//cout<<"nRoll = "<<roll;
cout<<"nfees = "<<fees;
//cout<<"nNo. of objects created : "<<count;
}
};
float calfeespaid(student s)
{
static float total;
total=total+s.fees;
return total;
}
main()
{
student s[5],a;
for(int i=0;i<3;i++)
{
s[i].setval();
calfeespaid(s[i]);
}
for( int i=0;i<3;i++)
{
//cout<<count;
s[i].showval();
}
cout<<"nTotal Fees Paid : "<<calfeespaid(a);
getch();
}
我们有班级学生的3个成员函数:1. setval:获取输入2. showval:显示输出3.calfeespaid:计算已支付的总费用
现在,我的目标是创建一个静态int变量count,它将计算setval函数中创建的对象的数量。
0,没有对象创建 ..........
相关文章:
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 具有包含其他对象的类的对象创建顺序
- 为什么我们再次从结构对象创建结构变量?
- 将对象创建为全局/静态对象会崩溃,而本地对象不会崩溃
- 如何创建一个对象创建函数,该函数将由与其关联的名称调用?
- 如何为自定义模板对象创建专门的函数模板
- 对象创建错误的C++矢量
- 如何为Python Swigged C++对象创建和分配回调函数
- 在 C++ 中为 C 样式对象创建一个透明包装类
- 此类模板的对象创建如何工作?
- C++ 中的对象创建类型有什么区别?
- 未知大小的数组作为类成员,用于在运行时(对象创建时间)创建数组的对象
- 如何仅通过父类对象限制对象创建
- 在正确性或良好的代码结构方面,这种动态对象创建看起来如何
- 无法将类对象创建为另一个类的成员
- 如何从现有基类对象创建派生类对象
- 在 DTor 之前删除的静态对象创建的线程?
- C++:定义多个构造函数时的对象创建/销毁序列
- 从对象创建矢量包装器,该对象只允许使用索引访问向量
- 是否可以为CPP中的对象创建一组指针