Sei sulla pagina 1di 20

Ishik University

Engineering Faculty
Computer Engineering Department

Final Project Report 1

C++ Language Programming Language


By:
Yasmin Sami Hayder
Date of submission
May,29,2018
Table of Contents
I.ntroduction ................................................................................................................................................ 3
I.I Definition of the language. Similar language. ..................................................................................... 3
I.II History: How it started, who defined the language, how became popular.................................. 3
I.III About this report (the layout of the report).................................................................................. 3
II.Practice from people. .............................................................................................................................. 3
II.I Which platforms it is used on. ......................................................................................................... 3
II.II What kind of application can be built with it. .............................................................................. 4
II.III Performance and comparison to other language in some family. ............................................. 4
II.IV Writability,readability,reliability and cost.................................................................................. 5
II.V Popularity of the language. ............................................................................................................ 5
II.VI Well- known application built with this language. ..................................................................... 6
II.VII Comments from famous people about language. ...................................................................... 7
III.Structure of the language...................................................................................................................... 7
III.I. Introduction.................................................................................................................................... 7
III.II. Data types of C++ language......................................................................................................... 7
III.III.Expressions and Assignment Statements................................................................................. 12
III.IV.Statement- Level Control Structures ....................................................................................... 17
References .................................................................................................................................................. 19
I.ntroduction
I.I Definition of the language. Similar language.
is a general-purpose programming language. It has imperative, object-
oriented and genericprogramming features, while also providing facilities for low-
level memory manipulation.
It was designed with a bias toward system programming and embedded, resource-constrained
and large systems, with performance, efficiency and flexibility of use as its design highlights.[1]
I.II History: How it started, who defined the language, how became popular.
C++ development standed in 1979, During the creation of Ph.D. thesis Bjarne Stroustrup worked
with language called simula. After that bjarne stroustrup started working on C language and added
more extra oop features to the classic C. His language included some add-on features such as:
 Classes.
 Basic inheritance.
 Default function arguments.
 Polymorphism.
Stroustrup state that the purpose of C++ is to make writing good programs easier and more pleasant
for the individual programmer. In 1983 the name of the language changed from C with classes to
C++. In the 1990s, C++ became one of the most used programming languages in the world. In
1998 the C++ standard committee published the first internal standard for C++ ,informally known
as C++98. In mid 2011 the new C++ stanard C++ 11 was published.The lastest version is C++17.
[2]

I.III About this report (the layout of the report).


Every one need a language to tell an information which is hidden, in such a way programming is
a language which is used used for knowing the hidden information of computer related to
programming.

II.Practice from people.


II.I Which platforms it is used on.
C++ cannot be run on any platform. It's the compiled machine code that runs on a platform. So it
depends on the compiler. If you can write a compiler which compiles C++ code to the native code
on that platform, then it will run on that platform.

To give some examples of platforms that C++ can be used with:

 OSes: Linux, Windows, Mac OS X, Free BSD, other POSIX-compliant OSes


 CPU Architectures: i386, PPC, IA32, IA64, Arm, etc.[3]

II.II What kind of application can be built with it.


We can create any progtam depending on our objective. To mention some example: Advance
Computations and Graphics: C++ provides the means for building applications requiring real-time
physical simulations, high-performance image processing, and mobile sensor applications. Maya
3D software, used for integrated 3D modeling, visual effects and animation, is coded in C++.[4]

Graphic User Interface (GUI) based applications: Many highly used applications, such as Image
Ready, Adobe Premier, Photoshop and Illustrator, are scripted in C++.[4]

Games: C++ overrides the complexities of 3D games, optimizes resource management and
facilitates multiplayer with networking. The language is extremely fast, allows procedural
programming for CPU intensive functions and provides greater control over hardware, because of
which it has been widely used in development of gaming engines. For instance, the science fiction
game Doom 3 is cited as an example of a game that used C++ well and the Unreal Engine, a suite
of game development tools, is written in C++.[4]

Medical and Engineering Applications: Many advanced medical equipments, such as MRI machines,
use C++ language for scripting their software. It is also part of engineering applications, such as
high-end CAD/CAM systems.[4]

II.III Performance and comparison to other language in some family.


Table 1: A Comparision of Common Programming Language.
languages Free level Implem Paradigm Purpose

Javascript Yes high interpreted Functional,inperative,object- web


oriented
C++ Yse high Compiled Procedural,functional,object- General
oriented,generic

C Yes low compiled Imperative ,structured General


Java Yes high compiled Structured,imperative,object- General
Oriented,generic,reflective,
Concurrent.
C# No high compiled Concurrent,event- General
driven,functional,generic,
Imperative, object-
Oriented, reflective
Assembly Yes low compiled imperative General
[5]
II.IV Writability,readability,reliability and cost.
 Readability
 C++ is a large language whichcomplicates its readability
 User defind operator overloading (aids and harms)
 Supports numeric as boolean expression affects readability
 Case sensitive, good control structure, more flexible iteration statements helps
readability
 Use of OOP improves its readability ade writability[6]
 Writability
 Its writability is highly associated with its readability
 C++ has rich data type and support abstraction improves writability
 Efficient expression helps writability
 Flexible and afficient control statement
 C++’s template improves writability[6]
 Reliability
 It is reliable if used carefully
 Flexibility and efficiency vs. reliability (not stronly typrd and does not have strict
type checking
 The use of pointer type is very flexible but could cause dangling pointer and
memory leaking
 Abstraction and information hiding improve its reliability
 Exception handing improves its reliable [6]
 Cost
 Hard to learn as it is a large language
 The cost of writing C++ depends on application .Generally,it is easy to write as
syntax is very straightforward.
 Backward compatible with c (low cost for C programmer)
 Cheaper oR free IDE reduces cost for training
 Inexpensive compliers decrease the cost of compilation and execution
 Flexible and efficiency speed up execution [6]

II.V Popularity of the language.


The index is updated once a month. The ratings are based on the number of skilled engineers
world-wide, courses and third party vendors. Popular search engines such as Google, Bing,
Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings. It is important
to note that the TIOBE index is not about the best programming language or the language in
which most lines of code have been written.
Figure 1:Tiobe’s Index as of May 2018.

[7]

II.VI Well- known application built with this language.


 Some application written in C++ language.
Adobe system
Most of the major applications of adobe systems are developed in C++ programming language.
These applications include Adobe Photoshop and Image Ready, Illustrator and Adobe Premier.
They’ve released a lot of open-source code in the past, always in C++, and their developers have
been active in the C++ community.
Google application
Some of the Google applications are also written in C++, including Google file system and
Google Chromium browser and MapReduce large cluster data processing.

 Some operating system written in C++


Apple – OS X operating system
Few parts of apple OS X are written in C++ programming language. Also few application for
iPod are written in C++.
Microsoft operating system
Literally most of the software are developed using various flavors of Visual C++ or simply C++.
Most of the big applications like Windows 95, 98, Me, 200 and XP are also written in C++. Also
Microsoft Office, Internet Explorer and Visual Studio are written in Visual C++. [8]
II.VII Comments from famous people about language.
 David Jameson.Author.
“The lastest new features in C++ are designed to fix the previously new features in C++”
 Richard A.O’Keefe.Computer scientist.
“Fifty years of programming languagre research,and we end we end up with C++”
 Robert Firth.
“C++ has its place in the history of programming language.Just as caligula has his place
in the history of the Roman Empire”
 James Gosling, c-inventor of Jave
 “James Godling, co-invebtor of java” [9]

III.Structure of the language.

III.I. Introduction.
A data structure is a group of data elements grouped together under one name. These data elements,
known as members, can have different types and different lengths.

Simple Example
struct product {
int weight;
double price;
};

product apple;
product banana, melon;[10]

III.II. Data types of C++ language.


All variables use data-type during declaration to restrict the type of data to be stored. Therefore,
we can say that data types are used to tell the variables the type of data it can store.[10]

1. Primitive Data Type.


These data types are built-in or predefined data types and can be used directly by the user to declare
variables. Example Primitive data types available in C++ are:

table 2:list of primitive types in c++


Type Keyward
Integer int
Character char
Boolean bool
Floating Point float
Double Floating Point double
Valueless or Void void
Wide Character wchar_t
[11]

2. Character Data Type.


Character: Character data type is used for storing characters. Keyword used for character
data type is char. Characters typically requires 1 byte of memory space and ranges from -
128 to 127 or 0 to 255.
Simple example

#include<iostream>
using nam()
{
char mychar="A";
cout<<mychar;
}
[12]

3. Enumeration Type.
An enumeration is a user-defined data type that consists of integral constants. To define an
enumeration, keyword enum is used.
Example
#include <iostream>
using namespace std;

enum suit {
club = 0,
diamonds = 10,
hearts = 20,
spades = 3
} card;

int main()
{
card = club;
cout << "Size of enum variable " << sizeof(card) << " bytes.";
return 0;
}[13]
4. Array Type.
C++ provides a data structure, the array, which stores a fixed-size sequential collection of
elements of the same type. An array is used to store a collection of data, but it is often more
useful to think of an array as a collection of variables of the same type.

Array are important to C++ and should need lots of more detail.There are following
few important concepts,which should be clear to a C++ programmer
 Multi-dimensional array
 Pointer to an array
 Passing arrays to function
 Return arrays to function

#include<iostream.h>
void main()
{
int a[4][4],i,j,s=0;
cout<<"Enter the elements of the matrix"<<endl;
for(i=0; i<4; i++)
for(j=0; j<4; j++)
cin>>a[i][j];

cout<<"The sum of the elements of the matrix=";


for(i=0; i<4; i++)
for(j=0; j<4; j++)
s=s+a[i][j];
cout<<s;

}[14]

5. Associative Arrays.
Associative arrays are also called map or dictionaries. In C++. These are special kind of
arrays, where indexing can be numeric or any other data type i.e can be numeric 0, 1, 2,
3.. OR character a, b, c, d… OR string geek, computers…
These indexes are referred as keys and data stored at that position is called
value.So in associative array we have (key, value) pair.
We use STL maps to implement the concept of associative arrays in C++.
Example
int[string] aa;

aa["hello"] = 3;
int value = aa["hello"];
assert(value == 3);
[15]

6. Record Types.
Records are used to group related component of different types. Component of the record are
called fields.
In C++
 Record called a struct(structure)
 Fields called members
 FieldName - the identifier used to refer to the field. The identifier only need to be
unique within the struct. It will not be in conflict with names usedlsewhere or in
other structs.Records have been implemented as classes in C++.

Example record type:

struct StudentType {
int idNumber;
char name[30];
StatusType status;
float credits;
float gpa;
};
StudentType student1;
StudentType student2;
[16]
7. Tuple Types.
A tuple is an object capable to hold a collection of elements. Each element can be of a
different type. A list of types used for the elements, in the same order as they are going to
be ordered in the tuple.
Example
#include <iostream>
#include <tuple>
int main ()
{
auto mytuple = std::make_tuple (10,'a');
std::tuple_element<0,decltype(mytuple)>::type first = std::get<0>(mytuple);
std::tuple_element<1,decltype(mytuple)>::type second = std::get<1>(mytuple);
std::cout << "mytuple contains: " << first << " and " << second << '\n';
return 0;
}[17]

8. List Types.
Table 3:Type of linked list.
linked list Double-linked list
Lists are sequence containers that allow Doubly linked lists can store each of the
constant time insert and erase operations elements they contain in different and
anywhere within the sequence, and unrelated storage locations. The ordering
iteration in both directions. is kept internally by the association to
each element of a link to the element
preceding it and a link to the element
following it.
.[18]

9. Union Types .
A union is a special data type where all members start at the same address. A union can hold
only one type at a time; therefore, you can save memory. A tagged union is a union which
keeps track of its types.
 Use unions to save memory.
 Avoid “naked”unions.
 Use anonymous unions to implement tagged unions.
 Don’t use a union for type punning.
Example
union Value {
int i;
double d;
};

Value v = { 123 };
cout << v.i << '\n';
v.d = 987.654;
cout << v.d << '\n'; This example is use union to save memory.[19]
10.Pointer and Reference Types.
Pointers, References and Dynamic Memory Allocation are the most powerful features in C/C++
language, which allows programmers to directly manipulate memory to efficiently manage the
memory - the most critical and scarce resource in computer - for best performance. However,
"pointer" is also the most complex and difficult feature in C/C++ language.
#include <iostream>
using namespace std;
int main() {
int number = 88; // Declare an int variable and assign an initial value
int * pNumber; // Declare a pointer variable pointing to an int (or int pointer)
pNumber = &number; // assign the address of the variable number to pointer pNumber
cout << pNumber << endl;
cout << &number << endl;
cout << *pNumber << endl;
cout << number << endl;
*pNumber = 99;
cout << pNumber << endl;
cout << &number << endl;
cout << *pNumber << endl;
cout << number << endl;
cout << &pNumber << endl;

}[20]
III.III.Expressions and Assignment Statements
1) Variable definition
A variable definition tells the compiler where and how much storage to create for the
variable. A variable definition specifies a data type, and contains a list of one or more
variables.
Figure 2: scope of variable.

Simple example:
//variable definition
int a,b;
double k;
//variable initializarion
a=10;
k=8.67;
[21]

2) Arithmetic expressions
Most programs perform arithmetic calculations. Figure 2. Summarizes the C++ arithmetic
operators. Note the use of various special symbols not used in algebra. The asterisk (*) indicates
multiplication and the percent sign (%) is the modulus operator that will be discussed shortly. The
arithmetic operators in Figure. 2are all binary operators, i.e., operators that take two operands. For
example, the expression number1 + number2 contains the binary operator + and the two
operands number1 and number2.
Simple example:
Algebraic y=mx+b
C++ y = m * x + b;

Table 3: Arithmetic operators.

C++ operation C++ arithmetic operator Algebraic expression C++ expression

Addition + f+7 f + 7

Subtraction - p–c p - c

Multiplication * bm or b · m b * m

Division / x / y
x / y or or x ÷ y

Modulus % r mod s r % s

[22]

3)Overloaded operators
C++ allows you to specify more than one definition for a function name or an operator in
the same scope, which is called function overloading and operator
overloading respectively.

Function overloading in c++.


You can have multiple definitions for the same function name in the same scope. The
definition of the function must differ from each other by the types and/or the number of
arguments in the argument list. You cannot overload function declarations that differ only
by return type.
Example
#include <iostream>
using namespace std;
class printData {
public:
void print(int i) {
cout << "Printing int: " << i << endl;
}
void print(double f) {
cout << "Printing float: " << f << endl;
}
void print(char* c) {
cout << "Printing character: " << c << endl;
}
};
int main(void) {
printData pd;

// Call print to print integer


pd.print(5);
// Call print to print float
pd.print(500.263);
// Call print to print character
pd.print("Hello C++");
return 0;}

operators overloading in C++


You can redefine or overload most of the built-in operators available in C++. Thus, a
programmer can use operators with user-defined types as well. Overloaded operators are
functions with special names: the keyword "operator" followed by the symbol for the
operator being defined. Like any other function, an overloaded operator has a return type
and a parameter list.
Overloadable/Non-overloadable
Figure 3: Following is the list of operators which can be overloaded.

Figure 4:Following is the list of operators, which can not be overloaded.


[23]

4) Type conversions
A conversion produces a new value of some type from a value of a different type. Standard
conversions are built into the C++ language and support its built-in types, and you can create user-
defined conversions to perform conversions to, from, or between user-defined types.
The standard conversions perform conversions between built-in types, between pointers or
references to types related by inheritance, to and from void pointers, and to the null pointer. For
more information, see Standard Conversions. User-defined conversions perform conversions
between user-defined types, or between user-defined types and built-in types. You can implement
them as Conversion constructors or as Conversion functions.
#include <iostream>
class Money
{
public:
Money() : amount{ 0.0 } {};
Money(double _amount) : amount{ _amount } {};
double amount;
};
void display_balance(const Money balance)
{
std::cout << "The balance is: " << balance.amount << std::endl;
}
int main(int argc, char* argv[])
{
Money payable{ 79.99 };
display_balance(payable);
display_balance(49.95);
display_balance(9.99f);
return 0;
} [24]
5) Relational and Boolean Expressions
Relational operators are used to compere value. All the expressions evaluates from left to
right.
Taible 1. List of operator in C++
Symbols meaning Example
< Less than (A>B) is true
<= Less than or equal (A<=B) is not true
> Greater than (A>B) is true
>= Greater than or equal (A>=B) is not true
== equal (A==B) is not true
!= Not equal (A!=B) is true

All operators evaluates results true or false. False statemant represent by 0 ,true statement
represent by 1.

Example
int a=5;
if(a<=7)
{
cout<<"true";
}
else

cout<<"false ";[25]

6) Assignment statement
It is essential that every variable in a program is given a value explicitly before any attempt is
made to use it. It is also very important that the value assigned is of the correct type.
The most common form of statement in a program uses the
 Assignment operator
 Expression or Constant assignment
variable = expression;
variable = constant;
The assignment statement:
total=total+5;
is thus a valid statement since the new value of total becomes the old value of total with 5 added
to it. Remember the assignment operator (=) is not the same as the equality operator in
mathematics (represented in C++ by the operator ==).[26]

III.IV.Statement- Level Control Structures


1) Selection statement:
 Makes a dicision and than takes an appropriate action based on that dicision.
 And also called dicision structure.
 Selection statements offer a choice between two or more excution.
 If statement
 Nested if ….else statement
 Switch statement
Nested if ….else example;
int grade=88;
if(grade>=90 && grade<=100)
cout<<"Your Grade is A+.";
else if(grade>=80 && grade<90)
cout<<"Your Grade is A.";
else if(grade>=70 && grade<80)
cout<<"Your Grade is B.";
else if(grade>=60 && grade<70)
cout<<"Your Grade is C.";
else if(grade>=50 && grade<60)
cout<<"Your Grade is D.";
else if(grade>=0 && grade<50)
cout<<"Your Grade is F.";
else
cout<<"Invalid Marks.";
Switch example;
Char grade= B;
switch(grade) {
case 'A' :
cout << "Excellent!" << endl;
break;
case 'B' :
case 'C' :
cout << "Well done" << endl;
break;
case 'D' :
cout << "You passed" << endl;
break;
case'F':
cout<<"you faild"<<endl;
default :
cout << "Invalid grade" << endl;
}
cout << "Your grade is " << grade << endl;

[27]

2) Ierative starement
 Directs computer to repeat one or more instruction until some condition met.
 Also called loop or iteration

 for loop
 while loop
 do…while loop
for loop example While loop example Do…while example
for(int i=1 ; i<10 ; i++) int i=1; int i=1;
{ While( i<10) do{
Cout<< i ; { cout<< i ;

} Cout<< i ;} }while(i<10);[27]
References

1.What is C++ ? definition and meaning .[online] A valiable at:


https://en.wikipedia.org/wiki/C%2B%2B

2. History: How it started, who defined the language, how became popular.[online] A valiable at:
http://www.cplusplus.com/info/history/

3. Which platforms it is used on.[online] A vailable at: https://www.quora.com/What-platforms-


does-C++-run-on

4.what kind of application can be build with it.[online] A vailable at:


https://www.invensis.net/blog/it/applications-of-c-c-plus-plus-in-the-real-world/

5. Performance and comparison to other language in same family.[online] A vailable at:


https://fusion809.github.io/comparison-of-programming-languages/

6. Writability,readability,reliability and cost. Evaluation of C++ programming language.[online]


A vailable at: http://slideplayer.com/slide/7689071/

7. Popularity of laguage.[online] A vailable at:https://www.tiobe.com/tiobe-index/8.Well- known


application built with this language.Best application and perating system written by C++.[online]
A vailable at: https://www.mycplus.com/featured-articles/top-10-applications-written-in-c-
cplusplus/

9. Comments from fomous people about language. [online] A vailable


at:https://en.wikiquote.org/wiki/C%2B%2B
10.Definition of data type..[online] A valiable http://www.cplusplus.com/doc/tutorial/structures/
http://www.cplusplus.com/doc/tutorial/structures/
11.Primitive Data Type. ..[online] A valiable at:
https://www.tutorialspoint.com/cplusplus/cpp_data_types.htm
https://www.geeksforgeeks.org/c-data-types/
12.Character Data Type. ..[online] A valiable at:https://www.geeksforgeeks.org/c-data-types/
13.Enumeration Type. ..[online] A valiable at:https://www.programiz.com/cpp-
programming/enumeration
14.Array Type. ..[online] A valiable at:https://www.tutorialspoint.com/cplusplus/cpp_arrays.htm
http://www.cplusplus.com/forum/general/41244/
15.Associative Arrays. ..[online] A valiable at:https://www.geeksforgeeks.org/associative-arrays-
in-cpp/
16.Record Types. ..[online] A valiable at:http://jcsites.juniata.edu/faculty/rhodes/cs2/ch05a.htm
17.Tuple Types. ..[online] A valiable
at:http://www.cplusplus.com/reference/tuple/tuple_element/
18.List Types. ..[online] A valiable at:http://www.cplusplus.com/reference/list/list/
https://www.cs.cmu.edu/~adamchik/15-121/lectures/Linked%20Lists/linked%20lists.html
19.Union Types. ..[online] A valiable at:http://www.modernescpp.com/index.php/c-core-
guidelines-rules-for-unions
20.Pointer and Reference Types. ..[online] A valiable at:
https://www.ntu.edu.sg/home/ehchua/programming/cpp/cp4_PointerReference.html
21.Variable definition…[online] A valiable
at:https://www.tutorialspoint.com/cplusplus/cpp_variable_types.htm
22.Arithmetic expressions..[online] A valiable
at:http://www.informit.com/articles/article.aspx?p=1705442&seqNum=6
23.Overloaded operators…[online] A valilable
at:https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm
24.Type conversions…[online] A valilable at:https://msdn.microsoft.com/en-
us/library/wwywka61.aspx
25.Relational and Boolean Expressions…[online] A valilable at:
https://www.slideshare.net/vieljoy/operators-expressions
http://www.cplusplus.com/doc/tutorial/operators/
26.Assignment statement …[online] A valilable at:http://www-
h.eng.cam.ac.uk/help/languages/C++/c++_tutorial/assignment.html
27. Statement- Level Control Structures…[online] A valilable at:
http://slideplayer.com/slide/7689071/
https://www.slideshare.net/satvirsandhu9/c-introduction-presentation

Potrebbero piacerti anche