Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    How to show up student's score? (C++)

    Coding Question & Answers
    2
    2
    12
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Seehoon Jang
      Seehoon Jang last edited by Seehoon Jang

             #include <iostream>
             #include <stdlib.h>
             using namespace std;
      
          class Sungjuk
          {
           private:
          char* name[30];
          int korean;
          int english;
          int math;
      
          int sum = 0;
          double average;
      
          public:
          Sungjuk()
          {
      	for (int i = 0; i < 30; i++)
      		name[i] = new char[12 * sizeof(char)];
          }
      
          void setName(char* name);
          char* getName();
      
          void setKorean(int kor);
          int getKorean();
      
          void setEnglish(int eng);
          int getEnglish();
      
          void setMath(int mat);
          int getMath();
      
          void compute(int korean, int english, int math)
          {
      	sum = korean + english + math;
      	average = sum / 3;
          }
      
      
      
          void output()
          {
      	cout <<"Total: "<< sum << endl;
      	cout << "Average: " << average << endl;
      
      	if (average >= 90)
      		cout << "Grade: A" << endl << "Result: Excellent..!" << endl;
      	else if (average >= 80 && average < 90)
      		cout << "Grade: B" << endl << "Result: Good..!" << endl;
      	else if (average >= 70 && average < 80)
      		cout << "Grade: C" << endl << "Result: Good..!" << endl;
      	else if (average >= 60 && average < 70)
      		cout << "Grade: D" << endl << "Result: Bad..!" << endl;
      	else
      		cout << "F : Bad..!" << endl;
          }
      
          ~Sungjuk()
          {
      	for (int i = 0; i < 4; i++)
      		delete[] name[i];
          }
          };
      
      
      
          void Sungjuk::setName(char* name)
          {
          this->name = name;
          }
          char* Sungjuk::getName()
          {
          return this->name;
          }
      
          void Sungjuk::setKorean(int kor)
          {
          this->korean = kor;
          }
          int Sungjuk::getKorean()
          {
          return this->korean;
          }
      
          void Sungjuk::setEnglish(int eng)
          {
          this->english = eng;
          }
          int Sungjuk::getEnglish()
          {
          return this->english;
          }
      
          void Sungjuk::setMath(int mat)
          {
          this->math = mat;
          }
          int Sungjuk::getMath()
          {
          return this->math;
          }
      
      
      
      
          int main()
          {
          Sungjuk obj;
      
          int kor, eng, mat, sum = 0;
          double avg = 0;
      
          cout << "input name: ";
          cin >> name;
          cout << "input korean, english, math: ";
          cin >> kor >> eng >> mat;
      
          obj.compute(kor, eng, mat);
          obj.output();
      
          system("PAUSE");
          return 0;
          }
      

      KakaoTalk_20200602_105915082_01.jpg KakaoTalk_20200602_105915082.jpg

      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by

        Hey @Seehoon-Jang I am confused on what is happening here. What is missing/not working? What is working?

        Reply Quote 0
          1 Reply Last reply

        • First post
          Last post