Anda di halaman 1dari 2

Before starting lecture 2 you should download IDE for C++.

You can download C++ by from this torrent http://thepiratebay.se/torrent/5267007.

In previous lecture we had some questions. We will look all these questions one by one. Q1. What is use of #include<iostream.h>? Ans:-iostream.h is library(there are many libraries in c++ like stdio.h, conio.h, strings.h , maths.h) and #include<iostream.h> open many functions like cout,cin. Without using #include<iostream.h> in your program compiler wont understand that what is use of cin and cout. With the use of iostream.h compiler understand that cin is input function and cout is output function. Q2.What is use of int main()? Ans:-Every operation in C++ is done in a function int main is also a function. Q3.Why we have written return 0? Ans:-In C++ every function should return a value except void .This will be more clear when we discuss about functions ins c++.Every program should have main function. Q4.Why we are using ; after every statement? Ans:-We use ; to terminate a line .Termination mean ending of command. When compiler encounters semicolon symbol it interprets that this is end of command.

Welcome To first Program


#include<iostream.h>//it opens a library #include<conio.h>// int main() { cout<<"Welcome to C++"<<endl;//output operator return 0;//return to int function } << is insertion operator. We will take another example of calculating sum of two numbers to better understand the C++ programs.

SUM OF TWO NUMBERS


#include<iostream.h> #include<conio.h> int main() { int a,b;//variables int sum;//variables cout<<"Enter the first value"<<endl;//output operator cin>>a;//input operator cout<<"Enter the second value"<<endl; cin>>b; sum=a+b;//sum of the values stored in a and b assign to summ cout<<"Sum is "<<sum<<endl;//output of summ return 0; }

Variables
Variables are used in C++ to store the values entered by user and storing the values done by compiler.In the above program a and b are the variables used to store the value entered by user and sum is used to store the value of sum of a and b. Now we will try to understand how the above program works. Our goal is to add two numbers entered by the user so we use Cout statement to prompt the user to enter the first value. Now the entered value is stored in variable a.We use similar concept for second number.Now in the tenth line sum of a and b is assigned to variable sum and we use that variable to display the sum. I hope now you can easily design any program. Try to solve these basic questions. Q1.Write a Program(WAP) to calculate average of two numbers? Q2.WAP to calculate the difference of two numbers. Q3.WAP that will ask for a temperature in Fahrenheit and display it in Celsisus? Q4.WAP to calculate maximum of two numbers? Try to solve these question on notebook first?

Anda mungkin juga menyukai