Introduction & Execution of 1st code

Introduction: 

The language that the operating system understands is different from any human language or programming language. This is called “machine language”. Writing programming codes to communicate with the machine using machine language is a tedious task that require number of programming instructions.

Writing, Executing and Saving a C++ Code:

Every student must familiar with typing, execution and saving of a C++ code. The software which the student will be use for developing C++ code is Microsoft Visual Studio 2013.

Visual C++ Editor:

This creates a C++ file in which you will have to enter your C++ code.

Visual C++ Compiler:

Compiler is used to convert high level language into low level language.

Comments:

Any statement written inside /*   */ this or outside this // called comments C++ compiler did not translate these comments.

Pre-processing Directive:

The first line written in C++ workspace is #include<iostream> this is called pre-processing directive. These directives cause the source program to be modified before compiling process begins.

void main( )/ int main( ):

This statement indicates the declaration of a main method or main function header. Any thing written inside these parenthesis is part main method.

cout<<“Hello World”:

The cout statement prints Hello World on the output screen.

Assignment 1:

Q 1:Display your name,registration number and session on the output screen

code:

#include<iostream>
using namespace std;
int main()
{
//name
cout << “Ahmed Mujtaba” << endl;
//registration no.
cout << “0015” << endl;
//session
cout << “Fall 2016” << endl;
system(“pause”);
return 0;}
Untitled

Q 2:Display addition ,subtraction and division of two numbers on the screen

Code:

q2

q2.

Q 3:Calculate the following

  1. (4+6)*(8+9)
  2. 5*(13+89) – (34 – 12)
  3. (12+7) / 9 – (45 + 11) / 6

Code:

q3

q3.

C++ data types and Arithmetic Operations

C++ Data Types:

The most common data types that will be used in C++ Programming are int,double,float,char,bool,etc. Data types define the nature of a declared variable.

Data Type                                             Use

1)double or float                           decimal values

2)char                                             character variables

3)int                                                         integers

Arithmetic Operations:

In C++ arithmetic operations are used to perform mathematical calculations such as +, -, *, /.

cin>> __:

This command is used to take input from user.

Assignment 2:

Q 1: Take two integers from the user and implement addition,subtraction and division

Code:

q21

q21..png

Q 2: Determine the value of y=a^3+b^3+c^3+3abc(a+b+c) .Take the variables from user

Code:

q22.png

q22.

Q 3:Implement a code to convert x kg into y pounds. (1 kg=2.204 pounds)

Code:

q23

q23..png

Control and Conditional statements

If statement:

The most common conditional statement is If statement. It allows the program to make a decision on true and false condition of the statement.

If else statement:

The if-else selection statement allows the programmer to specify the different actions are to be performed if the condition is true than when condition is false.

Nested If-else:

                            Nested if-else refers to implementing an if-else block within another if or else block.

Assignment 3:

 Q 1: Implement a program which decides if a number enter from user is divisible by 2.

Code:

q1

q1.

Q 2: Determine the roots of a quadratic equation.

Code:

q2

q2.

Q 3: Determine number is even or odd.

Code:

q3

q3.

While and Do-While Loop

Introduction:

While Loop:

The while repetition allows the user to execute a particular set of instructions repeatedly while some conditions remain true. The while loop is very similar to for loop. The syntax of a general while loop is as follows:

Syntax:

initialization;

while(condition)

{

statement( );

update;

}

Do-While:

Every while loop can be converted into a do-while but not vice versa. The reason is that the do-while loop always executes at least once. The basic syntax for the do-while is.

Syntax:

initialization;

do

{

statement( );

update;

}while(condition);

Assignment 5:

Q 1:Determine the number enter by user is a palindrome or not.

Code:

q1.png

q1..png

Q 2:Count how many 5 are present in series.

Code:

q3.png

q3..png

For Loop

Introduction:

The for repetition statement handles all the details of counter-controlled repetition. The for loop consists of three parts initialization,condition and update.

Syntax:

for(initialization ; condition ; update)

{

statements(  );

}

Assignment 4:

Q 1:Implement a program that calculates the sum of all integers from 0 to 10.

Code:

q1.png

q1.

Q 2:Implement a program using for loop that prints multiple of 5 from 0 to 100

Code:

q2

q2..png

Q 3:Implement a code that calculates the mathematical constant ‘e’ for power 1 and n terms taken by user.

Code:

q4

q4.

Q 4:Determine the factorial of a number  entered by user.

Code:

q5

q5.

 

Next page:

-Arrays

https://www.electricalengineering4u.com/fundamentals-of-programming/arrays-in-c/