Help

This is a discussion on Help within the C++ Programming forums, part of the General Programming Boards category; I have been asked to write a class of grades that contains members as subject marks and member functions set ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    112

    Help

    I have been asked to write a class of grades that contains members as
    subject
    marks

    and member functions
    set marks
    get marks
    set subject
    get subject
    calculate grade
    print grade

    from this class i have to use composition to create another class of student
    member

    name
    grades

    member functions

    set name
    get name

    insert marks // insert marks and subject name
    get result // to calculate the total marks
    print report // to print the name,, subject wise marks and total marks and grade

    here is the code

    kindly help me with the student class

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    class grade
    {
    char subject[20];
    int marks;
    
    public:
    
    void setmarks()
    {
    cout<<"Enter marks:";
    cin>>marks;
    }
    
    int getmarks()
    {
    return marks;
    }
    
    void setsubject(char t[20])
    {
    strcpy(subject,t);
    }
    
    char* getsubject()
    {
    return subject;
    }
    
    char calcgrade()
    { char g;
    if (marks<50)
    	g='F';
    else
    	g='A';
    return g;
    }
    
    void printgrade()
    {
    cout<<"Subject is:"<<subject<<"Marks are:"<<marks<<"Grade is:"<<calcgrade();
    }
    };
    
    class student
    {
    char name[20];
    grade a;
    
    public:
    
    void setname(char p[20])
    {
    	strcpy(name,p);
    }
    char* getname()
    {
    	return name;
    }
    
    int insertmarks()
    {
    
         {
         a.getmarks();
         return a.getmarks();
        }
    }
    
    
    int getresult()
    { int total;
    
    	total=total+insertmarks();
    
    	return total;
    }
    
    
    void getreport()
    {
    	cout<<"Name is :"<<name;
    
    	cout<<"Total marks are"<<getresult();
    
    }
    };
    
    int main()
    {
    student a;
    clrscr();
    a.setname();
    a.insertmarks();
    a.getresult();
    a.getreport();
    getch();
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    So what specifically do you need help with?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    112
    member functions
    insert marks
    getresult
    get report

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Sooo...pretty much everything then. Right.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21