You are on page 1of 24

C++ , course

session 1

by: Mostafa Ashraf


Name : Mostafa Ashraf Mohamed.

education : electrical computer engineer “Ain Shams un ”.

Mail : mostaphaashraf1996@gmail.com

bio : I have some skills In programming like~ C , C++ , java ,


python , matlab ,microcontroller{avr,arm}, object oriented
program “oop”,gui python{tkinter}, web designer.
problem solving: “acm”,“hackrrank”

Courses : java concepts. ministry of defence "information


system “ , and online courses .

projects: linear,diffrenital equation solving , Rc car ,


graphics classes shapes , and another projects.
Programming
C++
After C++
Flow of course:

 will explaining a course content putted on page and very


important side topics
 1- Session and examples in it.
 2- Sheets.
 submit sheet at: assignmentsubmitted83@gmail.com
 3- Assignments and online Exam.
 Will use a visual Studio or code blocks for code.
 Big C++ reference.
 Online problem solving website:
 hackerrank but sheets satisfied yet
Let’s Start
Some declaration :

* We have a much data type that’s represent data inserts in computer .


numbers , sentences , pictures , etc….

* the computer is very stupid , and its language is “0” . “1” , so how we can input data for
it .
Number Systems:
Cont. Number Systems:

1- binary system “base 2”: represents text, computer processor instructions, or any 
other data using a two-symbol system. The two-symbol system used is often the binary
number system's 0 and 1.

2- hexadecimal system “base 16 “ : is commonly used by programmers to describe locations
in memory because it can represent every byte, have values from 0-9 and A-F .

3- decimal system “base 10”: Decimal is a term that describes the base-10 number system, 
probably the most commonly used number system. The decimal number system consists of
ten single- digit numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The number after 9 is 10. The number
after 19 is 20 and so forth. Additional powers of 10 require the addition of another positional
digit.
4- octal system “base 8 ” : made from binary numbers , for example : 74 in decimal > in 
binary is 1001010 > in octal is 112 : 1*8^2 + 1*8^1 + 2*8^0 .
Range of Signed number = -((2^n-1)-1) ~ ((2^n-1)-1) 

Range of unsigned number = 0 ~ ((2^n)-1) 


Data Types : one byte = 8 bits

We have much data types in programming: 


Hello world! ,Program.
#: called directives and are processed by
preprocessor which is a program invoked by the
compiler.
Include : copy and import
Iostream : stands for Input Output Stream. It is basically
#include <iostream> 
a header file in C++ standard Library. If you want to
using namespace std;  add streams in your program you need to include it. It
provides basic input and output services for C++
int main() 
programs.
{ Std : standard scope .
Namespace: is a feature added in C++ and not
cout << "hello world\n"; 
present in C. A namespace is a declarative region
system("pause");  that provides a scope to the identifiers (names of the
return 0;  types, function, variables ,etc) inside it.
Multiple namespace blocks with the same name are
allowed. All declarations within those blocks are
}  declared in the named scope.
Int main (){} : C++ standard requires main() to
return int”0” , for make sure the program is done .
Special characters :

1- “\n “ print a new line . 


2 – “\t” print 7 white space . 

3- “ \” ” print a double quote 

4- “ \’ “ print single quote . 

5- “ \a “ make a bell . 
6 – “ \b “ move a back space . 
arithmetic operations:
Cin>> ; and Cout<< ;

#include <iostream> 
Using namespace std ; 
int main (){
string x ; // Booking a 4 bytes in memory 

cin >> x ; // make input for x 


cout << x << endl; // show me what is in x

System(“pause”); // make pause for program to don’t close when end 


Return 0 ; // that’s value return when program is done 
}
Some calculation program.

#include <iostream> 
using namespace std ;
int main (){
Int x , y , z ; 
cin >> x >> y ;
z = x +y ; cout << z <<“\n”;
z = x-y ; cout << z <<“\n”;
z=x*y ; cout << z <<“\n”; 
z= x/ y ; cout << z <<“\n”;
z = x%y ; cout << z <<“\n”;
z = x++ + -- y ; cout << z <<“\n”;
x+= 1 ; y -= 2 ;
cout << x << “ ” << y << “\n” ;
system (“pause”); return 0 ;
} 
exercise (1) : math calculation by
“math.h”
#include <iostream> 
#include<math.h> // it’s a library make an activation for difrrance math operations. 
Using namespace std; 

Int main(){ 
Int a , b , c ; 

C = sin (a); cout << c << endl; //can use another Trigonometric functions ,cos,tan,asin, etc.. 
C = abs(a-b); cout << c << endl; // compute absolute values 
C = sinh (a) ; cout << c << endl ; // can use another Hyperbolic functions , cosh , tanh , etc.. 
C = pow(a,b) ; cout << c << “\n”;// can use another power functions , sqrt , cbrt , hypot . 
C = exp(b) ; cout << c << “\n”; // can use another Exponential and logarithmic functions . 
Return 0 ; } 
Problems :
1- Write a C++ program that for a given number of apples, tells the user how many dozens of 
apples(s) he has and how many extra apples are left over.
For Example: if the number of apples = 40, the output should be: 3 dozens and 4 apples 
2 - Write a C++ program Count Change to count change. Given the number of quarter, 
dimes, nickels and cents the program should output the total as a single value in dollars and
cents.
Hint: 

● One dollar corresponds to 100 cents ● One quarter corresponds to 25 cents 

● One dime corresponds to 10 cents 

● One nickel corresponds to 5 cents 

For example if we have: 3 quarters, 2 dimes, 1 nickel and 6 cents, the total is 1.06 dollars. 
Cont. problems :

3 - The Pythagorean Theorem states that the sum of the squares of the two sides of the right 
angle triangle is equal to the square of the hypotenuse.
For example: 3, 4 and 5 are sides of the right angle triangle as they form a Pythagorean 
Triple (52 = 42 + 32)
Given 2 numbers, m and n where m >= n, a Pythagorean Triple can be generated by the 
following formulae:
a = m^2 – n^2 

b = 2mn 

c = root ( a^2 + b ^ 2 ) 

Write a C++ program that prints the values of the Pythagorean Triple generated by the 
formulae above, given m and n.
Out Lines:

1- introduction 

2 – number systems 

3 – Data Types 
4- Ascii table 

5 – Hello world program 

6 – arithmetic operations 

7 - cin , cout 

8 – exercise and some problems 

You might also like