firdaus_84 Publish time 21-7-2006 06:21 PM

Basic Programming Question - Class

OK guys, I stumble in one big problem now. Among all of questions inside myassignment this question suck me up. So, I ask for any expert out there. Could youhelp me find any solution?? I need to submit it fast. I really need to know the solution guy. I really appreciated any help now:

So, this is the question :

(a)        Write a complete program based on the information given below.
        (i)        Create a class called Marks.
        (ii)        Data member (set to private) : name(char), gpa(float) and grade(char)
                Member function : declare the member function in the class.
(a)char set_name()
•        Get name from user and set the value to name.
(b)float set_gpa()
•        Get the gpa from the user and set the value to gpa.
(c)float set_grade()
•        Calculate the Grade based on the following data.
o        GPA 3.00 to 4.00= grade 慉

shahnazz Publish time 21-7-2006 10:43 PM

nothing in this world is free nowadays... :bgrin:

zenslack Publish time 22-7-2006 02:38 PM

u have to learn how to make a class, do a simple one first. the question already stated all the stuffs needed in that class. I assume u want it in C++,


here's a sample class in PHP (warning, nvr been tested, this is one lazy saturday afternoon's work hehehe)



class Marks
{
        private $name;
        private $gpa;
        private $grade;
       
        function set_name($name_from_user_input)
        {
                $this->name        = $name_from_user_input;
        }
       
        function set_gpa($gpa_from_user_input)
        {
                $this->gpa = $gpa_from_user_input;       
        }
       
        function set_grade()
        {
                if ($this->gpa <= "3.00" && $this->gpa >= "4.00" ) {
                  
                        $this->grade = "A";                       
                       
                } elseif ($this->gpa >= "2.00" && $this->gpa <= "2.99") {
               
                        $this->grade = "B";
                  
                } elseif ($this->gpa >= "0.00" && $this->gpa <= "1.99") {
                  
                        $this->grade = "F";
               
                } else {
                         
                          $this->grade = "Wrong";
                }
        }
}

Asiafever Publish time 22-7-2006 06:51 PM

Is this another way of writing class definition in C++?? Seem so different...Are you writing pseudocode or the real C++ code?

alien3d Publish time 23-7-2006 01:13 PM

hehe

That's above are php code
Nah baca link tutorial oop
Basic Programming Melayu
http://alien3d.dotgeek.org/pengatucaraan.swf

Advance oop
http://alien3d.dotgeek.org/oop.swf
C++ takde $this->function
c++namaclass->function atau namaclass::function
php are simmilir dengan c tapi senang lagik

zenslack Publish time 23-7-2006 02:04 PM

php - scripting language, tapi underneath php memang C

C++ full OOP programming language

LimpBizkutMerri Publish time 23-7-2006 08:36 PM

Originally posted by firdaus_84 at 21-7-2006 06:21 PM
OK guys, I stumble in one big problem now. Among all of questions inside myassignment this question suck me up. So, I ask for any expert out there. Could youhelp me find any solution?? I need to...

inheritance yerk???

nuwa Publish time 23-7-2006 10:16 PM

canggih-canggih semuanya

shahnazz Publish time 23-7-2006 10:49 PM

apa pulak inheritance? basic object / class definition & implementation aje.

ultra78 Publish time 24-7-2006 11:16 PM

Originally posted by shahnazz at 23-7-2006 10:49 PM
apa pulak inheritance? basic object / class definition & implementation aje.
:ah: object & property

LimpBizkutMerri Publish time 24-7-2006 11:42 PM

Originally posted by shahnazz at 23-7-2006 10:49 PM
apa pulak inheritance? basic object / class definition & implementation aje.

ingatkan leh gune inherintance kot..kekekee..luper plak.. simple program..

fnd99 Publish time 24-7-2006 11:44 PM


C++ full OOP programming language


Nope, C++ is not full OOP programming language, contoh yg full OOP programming language adalah JAVA Programming... C++ semi full OOP

LimpBizkutMerri Publish time 25-7-2006 01:01 PM

tkde org nka tulon ke..??kekekee.. cian dierrr..

otai_g Publish time 15-9-2010 06:19 PM


#include <iostream>
using namespace std;

class Marks {
private:
        char name;
        float gpa;
        char grade;
public:
        char* set_name();
        float set_gpa();
        float set_grade();
};

char* Marks::set_name()
{
        cout<<"Enter name : ";
        cin.getline(name,256);
        return name;
}

float Marks::set_gpa()
{
        cout<<"Enter gpa : ";
        cin>>gpa;
        return gpa;
}

float Marks::set_grade()
{
        if (gpa>=3 && gpa<= 4) grade = 'A';
        if (gpa>=2 && gpa<= 2.99) grade = 'B';
        if (gpa>=0 && gpa<= 1.99) grade = 'C';
        return grade;
}

void main()
{
        char *nama, greda;
        double markah;

        Marks M;

        nama=M.set_name();
        markah=M.set_gpa();
        greda=M.set_grade();

        cout<<"\n=============================="<<endl;
        cout<<"\tResult Slip"<<endl;
        cout<<"=============================="<<endl;
        cout<<"Name : "<<nama<<endl;
        cout<<"Gpa : "<<markah<<endl;
        cout<<"Grade : "<<greda<<endl;
}
Pages: [1]
View full version: Basic Programming Question - Class


ADVERTISEMENT