Click here to Skip to main content
14,577,466 members
Rate this:
Please Sign up or sign in to vote.
See more:
#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;
        }


What I have tried:

above thing is what I tired..
I need to show up one student's score for first cpp

and show up three student's scores for second cpp.
Posted
Updated 1-Jun-20 20:40pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
Help me to coding to show up student's score using visual C++

You forgot to explain what is wrong (not working as expected) in your code.

You can simplidy the cascade of tests
if (average >= 90)
    cout << "Grade: A" << endl << "Result: Excellent..!" << endl;
else if (average >= 80 && average < 90) // you reach this point because previous test failed, so you already know that average < 90
    cout << "Grade: B" << endl << "Result: Good..!" << endl;
else if (average >= 70 && average < 80) // you reach this point because previous test failed, so you already know that average < 80
    cout << "Grade: C" << endl << "Result: Good..!" << endl;
else if (average >= 60 && average < 70) // you reach this point because previous test failed, so you already know that average < 70
    cout << "Grade: D" << endl << "Result: Bad..!" << endl;
else
    cout << "F : Bad..!" << endl;
}

which gives
if (average >= 90)
    cout << "Grade: A" << endl << "Result: Excellent..!" << endl;
else if (average >= 80)
    cout << "Grade: B" << endl << "Result: Good..!" << endl;
else if (average >= 70)
    cout << "Grade: C" << endl << "Result: Good..!" << endl;
else if (average >= 60)
    cout << "Grade: D" << endl << "Result: Bad..!" << endl;
else
    cout << "F : Bad..!" << endl;
}

Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
Indentation style - Wikipedia[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
   
Comments
Seehoon Jang 1-Jun-20 22:09pm
   
void Sungjuk::setName(char* name)
{
this->name = name;
}
char* Sungjuk::getName()
{
return this->name;
}

it shows up red underline on 'this'->name =name;
Seehoon Jang 1-Jun-20 22:11pm
   
https://askavan.com/topic/113/how-to-show-up-student-s-score-c

I couldn't post image on here..
Patrice T 1-Jun-20 22:16pm
   
Use Improve question to update your question.
So that everyone can pay attention to this information.
Rate this:
Please Sign up or sign in to vote.

Solution 2

What is the significance of the numbers 30, 12, and 4 ? You are using this code in the constructor?
for (int i = 0; i < 30; i++)
    name[i] = new char[12 * sizeof(char)];
and that makes no sense. The variable is declared as :
char* name[30];
That is thirty pointers to characters. I seriously doubt that is what you want. You appear to be asking for one string that is the name. Why allocate 12 characters? It would make more sense to declare the name as just a character array like this :
char name[ NameSize + 1 ];


I asked about those three numbers because that is very bad form. Those should be constants. If you use this declaration you need only one constant and you can get rid of the construction and deletion. Since this is C++, it would be best to use a std::string to hold the name. Actually, you don't do anything with the name so you really don't need it at all.

Lastly, calling system should be done only on the rare occasions when no viable alternative is available. This does not qualify. It would be much better to call getchar() or a similar function to wait for a keyboard entry.
   
Comments
Rick York 2-Jun-20 0:09am
   
I guess I was too late. Oh well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100