c++ Project in + theory

6
  AIRWAYS RES ERVATIO N SYSTEM PROJECT Description: This Project is like online ticket booking of airways. PREPARED BY: This is a simple Flight Reservation program using C++. Here we are defining a class called flight and it has two functions. book , availability  which are used for  booking tickets and other is used for checking availability respectively. We are defining tickets in static because we need to have tickets value to be the same in the whole program. Alternatively we can also initialize tickets in t he class by defining it in a function and passing the parameters as we should not init ialize a variable in the class. We are setting the tickets value to 80, that means the maximum number of tickets available are 80 in the flight. book  function is used to book the functions, first we need to check the tickets count. The tickets count must be less than or equal t o 80 and more t han 0. If this condition is met, then we’ll ask the user How many tickets he/she wa nts. Then we are checking for the tickets available and subtracting the number from total tickets. availability  function is used to print the tickets variable value. In main  function, we are using a switch cas e to take the user input in order to direct the user appropriately.  Index:  Compilers Basics of C++  Structure of a program  Variables and types  Constants  Operators  Basic Input/Output Program structure  Control Structures  Functions  Overloads and templates  Name visibility Compound data types  Arrays  Character sequences  Pointers  Dynamic Memory  Data structures  Other data types Classes  Classes (I)  Classes (II)  Special members  Friendship and inheritance  Polymorphism Other language features  Type conversions 

Transcript of c++ Project in + theory

Page 1: c++  Project in + theory

8/12/2019 c++ Project in + theory

http://slidepdf.com/reader/full/c-project-in-theory 1/6

  AIRWAYS RESERVATION SYSTEM PROJECTDescription:

This Project is like online ticket booking of airways.

PREPARED BY:

This is a simple Flight Reservation program using C++. Here we are defining a class called flight and it has two functions. book , availability  which are used for

 booking tickets and other is used for checking availability respectively. We are defining tickets in static because we need to have tickets value to be the same in the

whole program. Alternatively we can also initialize tickets in the class by defining it in a function and passing the parameters as we should not init ialize a variable in

the class. We are setting the tickets value to 80, that means the maximum number of tickets available are 80 in the flight.

book  function is used to book the functions, first we need to check the tickets count. The tickets count must be less than or equal to 80 and more than 0. If this

condition is met, then we’ll ask the user How many tickets he/she wants. Then we are checking for the tickets available and subtracting the number from total tickets.

availability  function is used to print the tickets variable value.

In main  function, we are using a switch case to take the user input in order to direct the user appropriately.

 Index:

  Compilers 

Basics of C++

  Structure of a program 

  Variables and types 

  Constants 

  Operators 

  Basic Input/Output 

Program structure

  Control Structures 

  Functions 

  Overloads and templates 

  Name visibility 

Compound data types

  Arrays 

  Character sequences 

  Pointers 

  Dynamic Memory 

  Data structures 

  Other data types 

Classes

  Classes (I) 

  Classes (II) 

  Special members 

  Friendship and inheritance 

  Polymorphism 

Other language features

  Type conversions 

Page 2: c++  Project in + theory

8/12/2019 c++ Project in + theory

http://slidepdf.com/reader/full/c-project-in-theory 2/6

  Exceptions 

  Preprocessor directives 

C++ Standard Library

  Input/Output with files 

C++/Introductionis one of the most popular, widely-used programming languages. It is a h igh level, object oriented language that is often used in production of commercial software programs. As such, it is a “hot”

technology that, in the job market, is very useful to know.

C++ is, in many ways, similar to java and C# programming languages.

Let us understand how A programming language works in given below example.

 A software program or application consists of a sequence of instructions that tells a computer what to do. A cake recipe can be thought of as a

program with a list of instructions that tells a person what to do to make a cake. You can refer to the same cake recipe anytime you wish to make a

cake when you know the language the instructions are written in. A computer can refer to the same software program to repeat the same sequence of

instructions again later when the instructions are within the set of instructions the computer can follow. The set of instructions a computer can follow is

known as an instruction set.

 An instruction may need to receive input for a computer to do something, process the input as data, and return information as output. The output of

one instruction may be used as the input of another instruction. Input and output may be anything the computer is designed to do. A cake making

computer might need to know how many servings to make as input, inform you of how much of each ingredient is needed as output, and process the

ingredients to make cake.

 A programming language consists of the set of available instructions that can be used to tell a computer what to do and grammatical rules that when

followed can be used to create meaningful expressions, such as "1+1". The English language has grammatical rules that when fo llowed can be used to

create meaningful sentences from different types of words, like nouns and verbs. rules Language when grammar sense followed make are (Languages

make sense when grammar rules are followed). The importance of proper grammar should be clear.

 An expression is a sequence of one or more grammatically correct instructions that tell a computer what to do. A compiler  is a software program that

translates the meaning of expressions of a programming language into appropriate instructions for a computer. Anyone who understands how to write

expressions of a programming language can tell a computer what to do by using a compiler to do the translation, much like a person who knows both

Spanish and English can be a translator for people who only know English or Spanish. A person who understands and can use a programming

language to write software programs is called a programmer .

 An electronic calculator is one of the simplest forms of a computer with expressions consisting of numbers, mathematical operators and functions like

log() that can be combined together to a create mathematical expression that the calculator can process to return a result. The mathematical

expression "1+1", for example, consists of the instruction add which takes as input two numbers and when processed by the calculator returns "2" as

the result or output. However unlike calculators, the instructions of one computer may not mean anything to another computer, just as two people who

don't share a common language may not understand each other. Programming languages, like C++, make writing portable programs easier, through

translation of a consistent language into instructions that the target computer can process.

Page 3: c++  Project in + theory

8/12/2019 c++ Project in + theory

http://slidepdf.com/reader/full/c-project-in-theory 3/6

Expressions in C++ consist of numbers, operators, variables, functions, classes, enumerations and other things which make up the language. In

English, various punctuation marks end a sentence. In C++, a semicolon (;) ends all statements, such as "a=1+1;". A block is a group of statements

surrounded by open and closing curly brackets ({}). Blocks serve much the same purpose as paragraphs do in English.

History of C++The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for hisPh.D. thesis. One of the languages Stroustrup had the opportunity to work with was a language called Simula,

which as the name implies is a language primarily designed for simulations. The Simula 67 language - which was

the variant that Stroustrup worked with - is regarded as the first language to support the object-oriented

programming paradigm. Stroustrup found that this paradigm was very useful for software development, however

the Simula language was far too slow for practical use.

Shortly thereafter, he began work on "C with Classes", which as the name implies was meant to be a superset of

the C language. His goal was to add object-oriented programming into the C language, which was and still is a

language well-respected for its portability without sacrificing speed or low-level functionality. His language

includedclasses, basic inheritance, inlining, default function arguments, and strong type checking in addition to all

the features of the C language.

The first C with Classes compiler was called Cfront, which was derived from a C compiler called CPre. It was a

program designed to translate C with Classes code to ordinary C. A rather interesting point worth noting is that

Cfront was written mostly in C with Classes, making it a self-hosting compiler (a compiler that can compile itself).

Cfront would later be abandoned in 1993 after it became difficult to integrate new features into it, namely

C++exceptions. Nonetheless, Cfront made a huge impact on the implementations of future compilers and on the

Unix operating system.

In 1983, the name of the language was changed from C with Classes to C++. The ++ operator in the C language is

an operator for incrementing a variable, which gives some insight into how Stroustrup regarded the language.

Many new features were added around this time, the most notable of which are virtual functions, function

overloading, references with the & symbol, the const keyword, and single-line comments using two forward slashes

(which is a feature taken from the language BCPL).

In 1985, Stroustrup's reference to the language entitled The C++ Programming Language was published. That

same year, C++ was implemented as a commercial product. The language was not officially standardized yet,making the book a very important reference. The language was updated again in 1989 to include protected and

static members, as well as inheritance from several classes.

In 1990, The Annotated C++ Reference Manual  was released. The same year, Borland's Turbo C++ compiler would

be released as a commercial product. Turbo C++ added a plethora of additional libraries which would have a

considerable impact on C++'s development. Although Turbo C++'s last stable release was in 2006, the compiler is

still widely used.

In 1998, the C++ standards committee published the first international standard for C++ ISO/IEC 14882:1998, 

which would be informally known as C++98. The Annotated C++ Reference Manual  was said to be a large

influence in the development of the standard. The Standard Template Library, which began its conceptual

development in 1979, was also included. In 2003, the committee responded to multiple problems that were

reported with their 1998 standard, and revised it accordingly. The changed language was dubbed C++03. 

In 2005, the C++ standards committee released a technical report (dubbed TR1) detailing various features they

were planning to add to the latest C++ standard. The new standard was informally dubbed C++0x as it was

expected to be released sometime before the end of the first decade. Ironically, however, the new standard would

not be released until mid-2011. Several technical reports were released up until then, and some compilers began

adding experimental support for the new features.

In mid-2011, the new C++ standard (dubbed C++11) was finished. The Boost library project made a considerable

impact on the new standard, and some of the new modules were derived directly from the corresponding Boost

libraries. Some of the new features included regular expression support (details on regular expressions may be

Page 4: c++  Project in + theory

8/12/2019 c++ Project in + theory

http://slidepdf.com/reader/full/c-project-in-theory 4/6

found here), a comprehensive randomization library, a new C++ time library, atomics support, a standard

threading library (which up until 2011 both C and C++ were lacking), a new for loop syntax providing functionality

similar to foreach loops in certain other languages, the auto keyword, new container classes, better support for

unions and array-initialization lists, and variadic templates.

An Overview of Programs and Programming LanguagesIn order to better communicate to our computers what exactly it is we want them to do, we've developed a wide range of programming languages to

make the communication process easier.

Depending on the type of project, there are many factors that have to be considered when choosing a language. Here is a li st of some of the more

noteworthy ones:

  Compiled, interpreted, or JIT-compiledCompiled languages are translated to the target machine's native language by a program called a compiler. This can result in very fast

code, especially if the compiler is effective at optimizing, however the resulting code may not port well across operating systems and the

compilation process may take a while.

Interpreted languages are read by a program called an interpreter and are executed by that program. While they are as portable as theirinterpreter and have no long compile times, interpreted languages are usually much slower than an equivalent compiled program.

Finally, just-in-time compiled (or JIT-compiled) languages are languages that are quickly compiled when programs written in them need to

be run (usually with very little optimization), offering a balance between performance and portability.

  High or Low Level Level, in this case, refers to how much the nature of the language reflects the underlying system. In other words, aprogramming language's level refers to how similar the language is to a computer's native language. The higher the level, the less similar it

is.

A low-level language is generally quite similar to machine code, and thus is more suitable for programs like device drivers or very highperformance programs that really need access to the hardware. Generally, the term is reserved for machine code itself and assembly

languages, though many languages offer low-level elements. Since a low-level language is subject to all the nuances of the hardware it's

accessing, however, a program written in a low-level language is generally difficult to port to other platforms. Low level languages are

practically never interpreted, as this generally defeats the purpose.A high-level language focuses more on concepts that are easy to understand by the human mind, such as objects or mathematical

functions. A high-level language usually is easier to understand than a low-level language, and it usually takes less time to develop a program

in a high-level language than it does in a low-level language. As a trade-off one generally needs to sacrifice some degree of control over what

the resulting program actually does. It is not, however, impossible to mix high-level and low-level functionality in a language.

  Type System

A type system refers to the rules that the different types of variables of a language have to follow. Some languages (including most

assembly languages) do not have types and thus this section does not apply to them. However, as most languages (including C++) havetypes, this information is important.

o  Type Strength: Strong or Weak 

A strong typing system puts restrictions on how different types of variables can be converted to each other without any converting

statements. An ideal strong typing system would forbid implicit "casts" to types that do not make any sense, such as an integer toa Fruit object. A weak typing system would try to find some way to make the cast work.

o  Type Expression: Manifest or Inferred 

This deals with how the compiler/interpreter for a language infers the types of variables. Many languages require variables' types

to be explicitly defined, and thus rely on manifest typing. Some however, will infer the type of the variable based on the contexts

in which it is used, and thus use inferred typing.

o  Type Checking: Static or Dynamic If a language is statically typed, then the compiler/interpreter does the type checking once before the program runs/is compiled.

If the language is dynamically type checked, then the types are checked at run-time.

o  Type Safety: Safe or Unsafe 

These refer to the degree to which a language will prohibit operations on typed variables that might lead to undefined behavior or

errors. A safe language will do more to ensure that such operations or conversions do not occur, while an unsafe language willgive more responsibility to the user in this regard.

These typing characteristics are not necessarily mutually exclusive, and some languages mix them.

  Supported paradigms

A programming paradigm is a methodology or way of programming that a programming language supports. Here is a summary of a few

common paradigms:

o  Declarative 

A declarative language will focus more on specifying what a language is supposed to accomplish rather than by what means it is

Page 5: c++  Project in + theory

8/12/2019 c++ Project in + theory

http://slidepdf.com/reader/full/c-project-in-theory 5/6

supposed to accomplish it. Such a paradigm might be used to avoid undesired side-effects resulting from having to write one's

own code.

o  Functional Functional programming is a subset of declarative programming that tries to express problems in terms of mathematical

equations and functions. It goes out of its way to avoid the concepts of states and mutable variables which are common in

imperative languages.

o  Generic 

Generic programming focuses on writing skeleton algorithms in terms of types that will be specified when the algorithm is actuallyused, thus allowing some leniency to programmers who wish to avoid strict strong typing rules. It can be a very powerful

paradigm if well-implemented.

o  Imperative 

Imperative languages allow programmers to give the computer ordered lists of instructions without necessarily having to explicitly

state the task. It can be thought of being the opposite of declarative programming.

o  Structured 

Structured programming languages aim to provide some form of noteworthy structure to a language, such as intuitive control

over the order in which statements are executed (if X then do Y otherwise do Z, do X while Y is Z). Such languages generally

deprecate "jumps", such as those provided by the goto statement in C and C++.

o  Procedural Although it is sometimes used as a synonym for imperative programming, a procedural programming language can also refer to

an imperative structured programming language which supports the concept of procedures and subroutines (also known as

functions in C or C++).

o  Object-Oriented Object-Oriented programming (sometimes abbreviated to OOP) is a subset of structured programming which expresses programs

in the terms of "objects", which are meant to model objects in the real world. Such a paradigm allows code to be reused inremarkable ways and is meant to be easy to understand.

  StandardizationDoes a language have a formal standard? This can be very important to ensure that programs written to work with one compiler/interpreter

will work with another. Some languages are standardized by the American National Standards Institute (ANSI), some are standardized by the

International Organization for Standardization (ISO), and some have an informal but de-facto standard not maintained by any standardsorganization.

The Features of C++ as a LanguageNow that all the necessary theory has been covered, now it is possible to explain what C++ has to offer as a programming language. C++...

  ...is an open ISO-standardized language.

For a time, C++ had no official standard and was maintained by a de-facto standard, however since 1998, C++ is standardized by a

committee of the ISO. Their page may be accessed here. 

  ...is a compiled language.

C++ compiles directly to a machine's native code, allowing it to be one of the fastest languages in the world, if optimized.

  ...is a strongly-typed unsafe language.

C++ is a language that expects the programmer to know what he or she is doing, but allows for incredible amounts of control as a result.

  ...supports both manifest and inferred typing.

As of the latest C++ standard, C++ supports both manifest and inferred typing, allowing flexibility and a means of avoiding verbosity wheredesired.

  ...supports both static and dynamic type checking.C++ allows type conversions to be checked either at compile-time or at run-time, again offering another degree of flexibility. Most C++ type

checking is, however, static.

  ...offers many paradigm choices.C++ offers remarkable support for procedural, generic, and object-oriented programming paradigms, with many other paradigms being

possible as well.

Page 6: c++  Project in + theory

8/12/2019 c++ Project in + theory

http://slidepdf.com/reader/full/c-project-in-theory 6/6

  ...is portable. As one of the most frequently used languages in the world and as an open language, C++ has a wide range of  compilers that run on many

different platforms that support it. Code that exclusively uses C++'s standard library will run on many platforms with few to no changes.

  ...is upwards compatible with CC++, being a language that directly builds off C, is compatible with almost all C code. C++ can use C libraries with few to no modifications of

the libraries' code.

  ...has incredible library support.A search for "library" on the popular project-management website SourceForge will yield over 3000 results for C++ libraries. A link to the

results of the search may be found here.