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 慉 nothing in this world is free nowadays... :bgrin: 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";
}
}
}
Is this another way of writing class definition in C++?? Seem so different...Are you writing pseudocode or the real C++ code?
hehe
That's above are php codeNah 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 php - scripting language, tapi underneath php memang C
C++ full OOP programming language 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??? canggih-canggih semuanya apa pulak inheritance? basic object / class definition & implementation aje. Originally posted by shahnazz at 23-7-2006 10:49 PM
apa pulak inheritance? basic object / class definition & implementation aje.
:ah: object & property 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..
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 tkde org nka tulon ke..??kekekee.. cian dierrr..
#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]