Beruflich Dokumente
Kultur Dokumente
CT025-3-2
Learning Outcomes
By the end of this session, you should be able to:
create, debug and run a simple C++ program using main function create, debug and run a simple C++ program using a class
What is C++?
C++
evolved from C which evolved from 2 previous languages, BCPL & B provides capabilities for object-oriented programming
C++ systems
Program-development environment Language C++ Standard Library
CT025-3-2-PCPP (Programming Concepts in C++) Beginning with C++ Slide 5 (of 20)
Applications of C++
go through six phases:
edit preprocesses compile link load execute
Program is created in the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk
Preprocessor
Disk
Compiler
Disk
Linker
Disk
Primary Memory
Loader
Disk
Primary Memory
CPU
. . . . . .
CPU takes each instruction and executes it, possibly storing new data values as the program executes.
Beginning with C++ Slide 7 (of 20)
#include <iostream> using namespace std; int main( ) { cout<<Every age has a language of its own\n; return 0; }
Beginning with C++ Slide 8 (of 20)
5
6 7 8
header files
Contains the declaration of any library functions used e.g. <cmath> - sqrt()
Comments
Line comments // this is a line comment Block comments /* this is a block comment */
CT025-3-2-PCPP (Programming Concepts in C++) Beginning with C++ Slide 11 (of 20)
Identifiers
Variables data members Functions member functions
Beginning with C++ Slide 13 (of 20)
string getCourseName()
void displayMessage() cout<<Welcome to the grade book for\n <<getCourseName() <<!<<endl; }
private:
string courseName; };
CT025-3-2-PCPP (Programming Concepts in C++) Beginning with C++ Slide 16 (of 20)
Follow up assignment
1. Use the preprocessor directives to include the iostream and conio header files. Create a class called Student that will hold two public fields: one that holds credit hours and another that holds the grade point average. Create the main function and within it declare a Student object identified as oneSophmore. Also within the main function, write the statements that prompt for and allow entry of the Students data. Add the statements that display the data just entered.
2.
3.