Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ programming

  1. Sep 13, 2016 #1
    I wanted to know in c++
    when we learn advance c++ like class,constructors,inheritance,data file handling we should know how to implement a class ? in c++ before studying these topics?
     
  2. jcsd
  3. Sep 13, 2016 #2

    jedishrfu

    Staff: Mentor

    Writing a C++ program means you are writing a class using at least one constructor and maybe inherit from some parent class depending on what you're trying to do. These are basic concepts which you would learn before you learn how to handle file io.

    There are many tutorials available online, here is one such tutorial:

    http://www.cplusplus.com/doc/tutorial/program_structure/
     
  4. Sep 13, 2016 #3

    jtbell

    User Avatar

    Staff: Mentor

    Maybe you're using "writing a class using at least one constructor" to mean something different from what I would mean by it. I don't see any such thing in this program:

    Code (C):

    #include <iostream>
    #include <string>

    using namespace std;

    int main ()
    {
        string firstname;
        cout << "What's your first name? ";
        cin >> firstname;
        cout << "Hello, " << firstname << "!" << endl;
        return 0;
    }
     
    Although I have used the 'string' class by declaring the variable 'firstname', and have implicitly used the 'istream' and 'ostream' classes by using the predefined objects 'cin' and 'cout' respectively, I have not defined (implemented) any classes of my own.

    At this level, you can perform file I/O simply by using the predefined 'fstream' class which you can make available via '#include <fstream>'.

    If you're writing a program using a predefined framework for e.g. a Windows GUI program, then you may very well have to write your code as classes with specific names and member functions (methods) that are "used" by the other parts of the framework. That's not a matter of the C++ language itself, but rather a matter of the structure of the framework.
     
  5. Sep 13, 2016 #4
    thank you
     
  6. Sep 13, 2016 #5
    thank you
     
    Last edited by a moderator: Sep 14, 2016
  7. Sep 14, 2016 #6

    jedishrfu

    Staff: Mentor

    My apologies @jtbell as I'm a longtime Java programmer and haven't much done C++ in at least 20 years. Its true though that the C++ programs, we wrote were a part of a larger GUI framework where we subclassed our application from a standard class. The framework provided a connection to the many GUI events such as mouse movement, drag/drop and cut/copy/paste.
    (see Taligent OS: https://en.wikipedia.org/wiki/Taligent)

    To be fair though, using C++ in the manner of the simple examples shown is more about writing a C program that has been extended with C++ datatypes, operators and method overloading. C++ divided the community of programmers into application programmers and class designers. As programmers started to see the value of the Model-View-Controller design pattern. Class design because a central issue of C++ applications as you had to now consider how to use constructors, polymorphism and inheritance effectively.

    In contrast, Java does not allow a programmer to simply write a main() method to get started instead you must begin with a class in order to create your program. Some recent language architectures based on Java such as Groovy or Scala do allow for writing code without a class but in fact, the code is wrapped with a hidden class.
     
  8. Sep 14, 2016 #7

    QuantumQuest

    User Avatar
    Gold Member

    The whole thing in teaching C++ is - the usual one, the background in C family of languages. If the student / people learning programming, have no prior such knowledge or a fortiori, no programming background at all, the learning path must begin from first-things-first or in other words the procedural characteristics / features of the language (with or without comparisons to C) and then go to classes and the advanced topics based on them.

    On the other hand, if learner has at least an intermediate knowledge of C, there's no point to talk about procedural things in depth other than the syntactic differences between C - C++ and syntactic sugar. So, effectively classes can be taught way earlier, because this way, learner, does not learn how to program but how to really program with C++.

    Now, for the specific question about learning advanced concepts based on classes, it is obvious that one way or the other - referring to the above, student / learner has to know classes first.

    As a side point, I don't find much truth in that someone already familiar (intermediate - advanced) with C, has to unlearn many things in order to learn good C++ programming, as is often said. I - many years ago, first learned a good deal of C (I was following a such discipline), and then introduced to C++ and I found no need in the procedure, to unlearn almost anything.
     
  9. Sep 14, 2016 #8
    thanks i wanted to share you something https://coursetro.com/ it has java programming explaining concept and practising program and making android apps

    once again thanks for helping
     
  10. Sep 14, 2016 #9
    t


    thanks
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: C++ programming
  1. C program (Replies: 4)

  2. C Program (Replies: 3)

  3. C program (Replies: 0)

  4. C programming (Replies: 9)

  5. C++ program (Replies: 2)

Loading...