CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 4040|Reply: 13

Basic Programming Question - Class

[Copy link]
Post time 21-7-2006 06:21 PM | Show all posts |Read mode
OK guys, I stumble in one big problem now. Among all of questions inside my  assignment 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 慉
Reply

Use magic Report


ADVERTISEMENT


Post time 21-7-2006 10:43 PM | Show all posts
nothing in this world is free nowadays... :bgrin:
Reply

Use magic Report

Post time 22-7-2006 02:38 PM | Show all posts
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)



  1. class Marks
  2. {
  3.         private $name;
  4.         private $gpa;
  5.         private $grade;
  6.        
  7.         function set_name($name_from_user_input)  
  8.         {
  9.                 $this->name        = $name_from_user_input;
  10.         }
  11.        
  12.         function set_gpa($gpa_from_user_input)
  13.         {
  14.                 $this->gpa = $gpa_from_user_input;       
  15.         }
  16.        
  17.         function set_grade()
  18.         {
  19.                 if ($this->gpa <= "3.00" && $this->gpa >= "4.00" ) {
  20.                   
  21.                         $this->grade = "A";                       
  22.                        
  23.                 } elseif ($this->gpa >= "2.00" && $this->gpa <= "2.99") {
  24.                
  25.                         $this->grade = "B";
  26.                   
  27.                 } elseif ($this->gpa >= "0.00" && $this->gpa <= "1.99") {
  28.                   
  29.                         $this->grade = "F";
  30.                
  31.                 } else {
  32.                          
  33.                           $this->grade = "Wrong";
  34.                 }
  35.         }
  36. }
Copy the Code

Rate

1

View Rating Log

Reply

Use magic Report

Post time 22-7-2006 06:51 PM | Show all posts
Is this another way of writing class definition in C++?? Seem so different...Are you writing pseudocode or the real C++ code?
Reply

Use magic Report

Post time 23-7-2006 01:13 PM | Show all posts

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
Reply

Use magic Report

Post time 23-7-2006 02:04 PM | Show all posts
php - scripting language, tapi underneath php memang C

C++ full OOP programming language
Reply

Use magic Report

Follow Us
Post time 23-7-2006 08:36 PM | Show all posts
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 my  assignment this question suck me up. So, I ask for any expert out there. Could youhelp me find any solution?? I need to  ...


inheritance yerk???
Reply

Use magic Report

Post time 23-7-2006 10:16 PM | Show all posts
canggih-canggih semuanya
Reply

Use magic Report


ADVERTISEMENT


Post time 23-7-2006 10:49 PM | Show all posts
apa pulak inheritance? basic object / class definition & implementation aje.
Reply

Use magic Report

Post time 24-7-2006 11:16 PM | Show all posts
Originally posted by shahnazz at 23-7-2006 10:49 PM
apa pulak inheritance? basic object / class definition & implementation aje.

:ah: object & property
Reply

Use magic Report

Post time 24-7-2006 11:42 PM | Show all posts
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..
Reply

Use magic Report

fnd99 This user has been deleted
Post time 24-7-2006 11:44 PM | Show all posts
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
Reply

Use magic Report

Post time 25-7-2006 01:01 PM | Show all posts
tkde org nka tulon ke..??kekekee.. cian dierrr..
Reply

Use magic Report

Post time 15-9-2010 06:19 PM | Show all posts

  1. #include <iostream>
  2. using namespace std;

  3. class Marks {
  4. private:
  5.         char name[256];
  6.         float gpa;
  7.         char grade;
  8. public:
  9.         char* set_name();
  10.         float set_gpa();
  11.         float set_grade();
  12. };

  13. char* Marks::set_name()
  14. {
  15.         cout<<"Enter name : ";
  16.         cin.getline(name,256);
  17.         return name;
  18. }

  19. float Marks::set_gpa()
  20. {
  21.         cout<<"Enter gpa : ";
  22.         cin>>gpa;
  23.         return gpa;
  24. }

  25. float Marks::set_grade()
  26. {
  27.         if (gpa>=3 && gpa<= 4) grade = 'A';
  28.         if (gpa>=2 && gpa<= 2.99) grade = 'B';
  29.         if (gpa>=0 && gpa<= 1.99) grade = 'C';
  30.         return grade;
  31. }

  32. void main()
  33. {
  34.         char *nama, greda;
  35.         double markah;

  36.         Marks M;

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

  40.         cout<<"\n=============================="<<endl;
  41.         cout<<"\tResult Slip"<<endl;
  42.         cout<<"=============================="<<endl;
  43.         cout<<"Name : "<<nama<<endl;
  44.         cout<<"Gpa : "<<markah<<endl;
  45.         cout<<"Grade : "<<greda<<endl;
  46. }
Copy the Code
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

8-1-2025 11:45 AM GMT+8 , Processed in 0.317211 second(s), 33 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list