0% found this document useful (0 votes)
69 views7 pages

C

C++ is a programming language that is general purpose, statically typed, free-form, multi-paradigm and compiled. Renamed C++ in 1983, as a pun involving the increment operator. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features.

Uploaded by

Michael Boyd
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views7 pages

C

C++ is a programming language that is general purpose, statically typed, free-form, multi-paradigm and compiled. Renamed C++ in 1983, as a pun involving the increment operator. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features.

Uploaded by

Michael Boyd
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

C++ Programming Language What is C++?

C++ (pronounced see plus plus) is a programming language that is general purpose, statically typed, free-form, multi-paradigm and compiled. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features. Developed by Bjarne Stroustrup starting in 1979 at Bell Labs, C++ was originally named C with Classes, adding objectoriented features, such as classes, and other enhancements to the C programming language. The language was renamed C++ in 1983, as a pun involving the increment operator. History Bjarne Stroustrup, a Danish and British trained computer scientist, began his work on "C with Classes" in 1979. The idea of creating a new language originated from Stroustrup's experience in programming for his Ph.D. thesis. Stroustrup found that Simula had features that were very helpful for large software development, but the language was too slow for practical use, while BCPL was fast but too low-level to be suitable for large software development. When Stroustrup started working in AT&T Bell Labs, he had the problem of analyzing the UNIX kernel with respect to distributed computing. Remembering his Ph.D. experience, Stroustrup set out to enhance the C language with Simula-like features. C was chosen because it was generalpurpose, fast, portable and widely used. Besides C and Simula, some other languages that inspired him were ALGOL 68, Ada, CLU and ML. At first, the class, derived class, strong typing, inlining, and default argument features were added to C via Stroustrup's "C with Classes" to C compiler, Cpre. In 1983, the name of the language was changed from C with Classes to C++ (++ being the increment operator in C). New features were added including virtual functions, function name and operator overloading, references, constants, user-controlled free-store memory control, improved type checking, and BCPL style single-line comments with two forward slashes (//), as well as the development of a proper compiler for C++, Cfront. In 1985, the first edition of The C++ Programming Language was released, providing an important reference to the language, as there was not yet an official standard.[11] The first commercial implementation of C++ was released in October of the same year. Release 2.0 of C++ came in 1989 and the updated second edition of The C++ Programming Language was released in 1991. New features included multiple inheritance, abstract classes, static member functions, const member functions, and protected members. In 1990, The Annotated C++ Reference Manual was published. This work became the basis for the future standard. Late feature additions included templates, exceptions, namespaces, new casts, and a Boolean type. Features: 1) Classes: By using classes we can create user defined data types. In other words the class is the collection of set of data and code. The class allows us to do some things which are

polymorphism, inheritance, abstraction, encapsulation which are our next features. The objects are the instances of classes.

2) Inheritance: Inheritance allows one data type to acquire properties of other data types. Inheritance from a base class may be declared as public, protected, or private. If the access specifier is omitted, a class inherits privately, while a struct inherits publicly . This provides the idea of reusability that means we can add the new features to an existing class without modifying it. 3) Data Abstraction and Encapsulation: Encapsulation means hiding of data from the data structures or in other words wrapping up of data in single entity is known as Encapsulation. In this the data is not accessible to outside world and only the functions are allowed to access it. When we want to write the class in which we dont have the knowledge about the arguments used to instantiate it then we can use templates in C++. Abstraction can be defined as the act of representing essential features without including background details. 4) Polymorphism: it means that the one interface can be used for many implementation so that object can behave differently for each implementation. The different types of polymorphism are static (Compile time) and dynamic (Run time). ---------C++ STRUCTURE: --------#include <iostream> #include <string> using namespace std; int main() { string name = ""; cout << "Enter Your Name: "; cin >> name; cout << "Hello " << name << endl; return 0; }

---------VARIABLE DECLARATION---------

SYNTAX: type variable = initializaion; or type variable(initialization); EXAMPLE: int number = 99; or int number(99);

---------CONSTANTS--------Constants are just like other variables, its a data storage location. But unlike other variables, as its name implies, constants` values don`t change. TWO TYPES OF CONSTANTS -Literal Constants Ex. int myNum = 0987654321; -Symbolic Constants Ex. int myAge = 2014 - birthYear; DEFINING CONSTANTS WITH #define #define myNum 0987654321 DEFINING CONSTANTS WITH const const int myNum = 0987654321; ---------ENUMERATED CONSTANTS---------this feature enable you to create new types and then to define variables of those types whose values are restricted to a set of possible values. Example: enum Color { red, blue, green, black, white }; Here`s a Demonstration of Enumerated Constants..

----------------------------------------------------------------------------------#include <iostream> using namespace std; int main() { enum Days { sunday, monday, tuesday, wednesday, thursday, friday, saturday }; Days today; today = monday; if( today == sunday || today == saturday ) cout << "Oh yeah its weekend!" << endl; else cout << "God its school days-_-" << endl; return 0; }

---------I/O STATEMENTS --------Output Statements: std :: cout << "statements"; cout << "statements"; cout << variable; cout << "statements" << variable; //if you are using namespace std //to print variable (w/ namespace std) //to print a statement and a variable

Input Statements: std :: cin >> variable; or cin >> variable; //if you are using namespace std

------- Conditional Statements ---------The if statement by itself guards a block of statements so that theyre executed only when a condition is true. if (a < b) { // statements only executed when a < b } The if/else statement selects one of two blocks of statements to execute: if (a < b) { // executed when a < b } else { // executed when a >= b } The switch statement selects between many constant values, the values must be integer/ordinal values. switch (expression) { case 1 : // do this break; case 2 : // do that break; case 3: // do the other break; default:

// if no case selected }

---------ITERATION STATEMENTS--------The while loop may never execute. while (a < b) { // do this while a < b } A do-while loop always executes at least once. do { // do that while a < b } while (a < b);

A for statement combines loop initialization, test, and update in one place. int k; for(k = 0; k < 20; k++) { // do that 20 times }

---------CLASSES and OBJECTS--------A class is declared when member function prototypes and instance variables are provided, typically in a header file. The body of the member functions arent typically included as part of a declaration. class Simple { public: void display() { cout << "Hello World!" << endl; }

};

How to call a function inside the class? Here`s a full working sample program that demonstrates how to call a function inside the class.. #include <iostream> using namespace std; class SimpleClass { public: void display() { cout << "Hello World!" << endl; } }; int main() { SimpleClass SimpleObject; SimpleObject.display(); return 0; }

---------Namespaces--------Namespaces can be used to help you organize your classes. More importantly, it help programmers to avoid name classes when using more than one library.

Namespace sample{ Int sampleInt = 0; Char sampleChar = K; }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy