-1

「class::data member is private」エラーのチェックを手伝ってくれる人

#include <iostream>

using namespace std;

class Marks
{
    private:
            char * name;
            char * grade;
            float gpa;

    public:
           char* set_name(char * n)
           {

                name=n;
                cout<<"Enter name   :";
                cin>>name;

                return name;

           }

           float set_gpa(float g)
           {

                gpa=g;
                cout<<"Enter CGPA   :";
                cin>>gpa;

                return gpa;

           }

           char set_grade()

           {

                if(gpa>=3.00&&gpa<=4.00)
                {
                    grade[1]='A';
                }

                else if(gpa>=2.00&&gpa<=2.99)
                {
                    grade[1]='B';
                }

                else if(gpa>=0.00&&gpa<=1.99)
                {
                    grade[1]='F';
                }

                else
                {
                    cout<<"error"<<endl;
                }

                return grade[1];
           }
}M1;


int main()
{


    char name[20];
    char grade[1];
    float gpa;

    cout<<"=================================="<<endl;
    cout<<"         ENTER INFORMATION        "<<endl;
    cout<<"=================================="<<endl;

    M1.set_name(name);
    M1.set_gpa(gpa);
    M1.set_grade();

    cout<<"=================================="<<endl;
    cout<<"            RESULT SLIP           "<<endl;
    cout<<"=================================="<<endl;

    cout<<"Name     : "<<M1.name;
    cout<<"GPA      : "<<M1.gpa;
    cout<<"Grade    : "<<M1.grade;

    return 0;

}

エラー一覧

In function 'int main()':|
Line 9|error: 'char* Marks::name' is private|
Line 85|error: within this context|
Line 11|error: 'float Marks::gpa' is private|
Line 86|error: within this context|
Line 10|error: 'char* Marks::grade' is private|
Line 87|error: within this context|
Line 70|warning: unused variable 'grade'|
||=== Build finished: 6 errors, 1 warnings ===|
4

1 に答える 1