NOOB class question

This is a discussion on NOOB class question within the C++ Programming forums, part of the General Programming Boards category; Up until now i have avoided using classes but now that i am the point where i think it would ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    142

    NOOB class question

    Up until now i have avoided using classes but now that i am the point where i think it would be valuable to add classes to my programmes i have taken a look at them and thought, what the hell are these things used for ?

    i understand the basic idea of a class ( i think )

    you create the class name, then it consists of a public section that is readable to the entire programme then you have a private section that is only readable within the class and so ON!!.

    if i am right? what are some good aplications for a class?

    i just want a few explenasions to give me a better understanding?

    and if i am way of track please let me know too.

    cheers
    WhAtHA hell Is GoInG ON

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    what are some good aplications for a class?
    I doubt you have the knowledge yet to understand an answer to that question. Learn the mechanics. As you do, you'll soon learn how to use classes in your programs.

    By way of a simple example, using classes allows you to write meaningful and easily understandable statements like the following in your code:
    Code:
    myDuck.speak();
    Here is an example:
    Code:
    #include <iostream>
    using namespace std;
    
    class Duck
    {
    public:
    	void speak()
    	{
    		cout<<"quack, quaaaaack!"<<endl;
    	}
    };
    
    
    int main() 
    {
    	Duck myDuck;
    	myDuck.speak();
    
    	return 0;
    }
    Last edited by 7stud; 01-08-2007 at 10:42 PM.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    142
    Quote Originally Posted by 7stud
    I doubt you have the knowledge yet to understand an answer to that question. Learn the mechanics. As you do, you'll soon learn how to use classes in your programs.

    ok, will do.

    can you answer one thing for me tho,

    how usefull are classes in programmes?
    WhAtHA hell Is GoInG ON

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    how usefull are classes in programmes?
    When you use classes in your programs, you're doing what's called OOP(Object Oriented Programming). OOP is a whole different method of programming. It was hailed as a major advancement in computer programming, but there are people who say it needlessly complicates things. They say that "procedural programming"(which is when you don't use classes) is just as powerful.

    C++ is a full blown, hard core OOP language, so if you are learning C++ you should be learning how to use classes.
    Last edited by 7stud; 01-08-2007 at 10:51 PM.

  5. #5
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by wart101
    ok, will do.

    can you answer one thing for me tho,

    how usefull are classes in programmes?
    It is useful for writing a big projects which have a long lifecycle because the maintenability (dunno if the spelling is right ) is better than modular programming.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    142
    Quote Originally Posted by 7stud
    When you use classes in your programs, your doing what's called OOP(Object Oriented Programming). OOP is a whole different method of programming. It was hailed as a major advancement in computer programming, but there are people who say it needlessly complicates things, and that what is called "procedural programming"(which is when you don't use classes) is just as useful.

    C++ is a full blown, hard core OOP language, so if you are learning C++ you should be learning how to use classes.

    cool, this is a little of the subject but i want to clear my understanding of OOP,

    OOP is more of a umm, ........ how do i explain it, umm i'll just give an example an you tell me which one is more OOP,

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(){
    
    cout<<"please type a word to be searched > ";
    
    */
    
    in here you would write code to search the word requsted by the user
    
    /*

    a more OOP would use a function to do the search

    Code:
    #include <iostream>
    
    using namespace std;
    
    void serC(char a) {
    
    // search code in here
    
    }
    
    
    
    int main(){
    
    
    char a;
    
    cout<<"please type a word to be search > ";
    cin.get(a);
    
    serC(a);
    
    }

    Bla Bla Bla, then every time you want to search you can call that function, the objects being the function?

    i remember when i was little i used to programme on an old amstrad LOL, but to write the code it was line by line you couldn't call a part of the programme previously written exactly.

    is that what defines OOP?
    WhAtHA hell Is GoInG ON

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by wart101
    a more OOP would use a function to do the search

    Code:
    #include <iostream>
    
    using namespace std;
    
    void serC(char a) {
    
    // search code in here
    
    }
    
    
    
    int main(){
    
    
    char a;
    
    cout<<"please type a word to be search > ";
    cin.get(a);
    
    serC(a);
    
    }

    is that what defines OOP?
    No - it is what defined module programming. When you take the portion of the code that executes some action and make it a module (function in C) - it means you start using module approach to the programming.

    OOP is the next step
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    is that what defines OOP?
    No. If you don't have classes in your program, you are not doing OOP. OOP is object oriented programming. You create objects from the classes in your program. If you don't have any classes, you aren't creating any objects, and therefore you aren't doing OOP.

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by 7stud
    No. If you don't have classes in your program, you are not doing OOP. OOP is object oriented programming. You create objects from the classes in your program. If you don't have any classes, you aren't creating any objects, and therefore you aren't doing OOP.
    No so easy. Classes != OOP

    You can use OO approach in C, and you have classes and still work without OO approach...

    If you create classes to represent your objects, when your classes function as objects then you can say it is OOP... Not just OOP == classes
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    No so easy. Classes != OOP

    You can use OO approach in C, and you have classes and still work without OO approach...

    If you create classes to represent your objects, when your classes function as objects then you can say it is OOP... Not just OOP == classes
    I can't make any sense of that, so I doubt the op can either.

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    142
    Quote Originally Posted by 7stud
    I can't make any sense of that, so I doubt the op can either.
    LOL, so if i simply use classes i will then be using OOP?
    WhAtHA hell Is GoInG ON

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    I would say "yes", although that doesn't prevent you from doing OOP badly. Apparently vart would say "no" depending on what you do.

  13. #13
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Object-oriented programming (OOP) is a programming paradigm that uses "objects" to manage software complexity. It utilizes several techniques from previously established paradigms, including modularity, polymorphism, and encapsulation. Even though it originated in the 1960s, OOP was not commonly used in mainstream software application development until the 1990s. Today, many popular programming languages (such as Java, JavaScript, C#, C++, Python, PHP, Ruby and Objective-C) support OOP
    http://en.wikipedia.org/wiki/Object-...ed_programming

    1. there is no such word classes in the definition of OOP
    2. the support for OOP does not mean - you use it.
    3. To determine that you realy use OOP - you should search modularity, polymorphism, and encapsulation use in your code.

    For me OOP is more way of thinking than the concrete technics used. Classes are not OOP. They just provide the easy way to implement OOP in your code.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  14. #14
    Registered User
    Join Date
    Sep 2005
    Posts
    142
    Quote Originally Posted by vart
    http://en.wikipedia.org/wiki/Object-...ed_programming

    1. there is no such word classes in the definition of OOP
    2. the support for OOP does not mean - you use it.
    3. To determine that you realy use OOP - you should search modularity, polymorphism, and encapsulation use in your code.

    For me OOP is more way of thinking than the concrete technics used. Classes are not OOP. They just provide the easy way to implement OOP in your code.
    well you see thats what i thought OOP was, more a way of thinking than anything,

    if you are going to design a phone book programme what are some of the thing you will need

    1. a menu
    2. a way to add entries
    3. a way to search the entries and so on


    1. a function called menu

    2. file IO ios:ut is one object

    3. a function for string algorithyms.

    ATLEAST THATS HOW IT WAS EXPLAINED TO ME AMONG MANY OTHER EXPLENATIONS (bloody caps Lock)
    Last edited by wart101; 01-09-2007 at 03:35 AM.
    WhAtHA hell Is GoInG ON

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467
    I would perhaps be more lenient with the definition of OOP.

    Even without using any form of inheritance, I would say classes alone already provide a coding paradigm that deviates from normal procedural programming. Although I may be stretching it a little.

    On another account, I may only have two classes, inheritance and polymorphism, with the rest of my code being strictly procedural. What to say then apart from the fact something is wrong with me?

    The definition of OOP doesn't take into account such factors as grade (how much of it you should use). At its core it introduces the notion of an object, without which it would not be possible to develop with OOP in mind. As such, creating objects alone is programming in OOP... although not fully using its potential.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 05:08 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21