-8

需要数数。在 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 函数中创建的对象的数量。

4

1 回答 1

3

0,没有创建对象............

于 2013-01-10T09:08:22.123 回答