162x Filetype PDF File size 0.16 MB Source: indico.mpp.mpg.de
1 #include2 #include 3 4 class HelloWorld { 5 6 public: ++ 7 C ProgrammingforPhysicists 8 HelloWorld(){ 9 }; 10 11 ~HelloWorld() throw(){ 12 }; 13 14 const char * const Message() throw(){ 15 return mspText; Anintroduction to object oriented programming with 16 } 17 18 private: 19 20 static const char * const mspText; exercises 21 22 }; 23 24 const char * const HelloWorld::mspText="hello world"; 25 26 int main(int argc, char *argv[]){ 27 28 try{ 29 WS2010/2011—April4th–15th,2011 30 HelloWorld *hello=new HelloWorld; 31 std::cout << hello→Message() << std::endl; 32 33 } 34 catch(std::exception &e){ 35 36 std::cerr << e.what() << std::endl; PDDr.H.Kroha,Dr.J.Dubbert, Dr. M. Flowerdew 37 return 1; 38 39 } MPIMünchen 40 41 delete hello; 42 43 return 0; 44 45 } Technische Universität München Max-Planck-Institut für Physik Introduction Max−Planck−Institut ++ für Physik WhatisC (Werner-Heisenberg-Institut) • C++isamulti-purpose high level programming language • Extension and improvement of the C programming language • Allows definition of new data types (classes) • Supports object oriented programming • Supports generic programming (polymorphism) ++ Kroha, Dubbert, Flowerdew C ProgrammingforPhysicists —Introduction WiSe2010/2011–p.3 Max−Planck−Institut ++ für Physik WhylearnC ? (Werner-Heisenberg-Institut) • Popular wide-spread language • Object oriented - Simplifies of large projects - Re-usable code • High execution speed (compiled language) ++ Kroha, Dubbert, Flowerdew C ProgrammingforPhysicists —Introduction WiSe2010/2011–p.4
no reviews yet
Please Login to review.