Monday, March 28, 2011

::::|| VU ||:::: LearnC_lecture05

***********Lesson5************************

Date:28March2011

Author:Asad.Ali

Message:

Take your soul out of the way from cheristanity

*******************************************

 

**********************************

Today's Ajjenda

Reise the 1st 4 lectures with prectical approuch. 

**********************************

Respectalb students!

pechly lectures per agr aik tairana nazar daly jay to hum yeh kehny k 

qabil hain k ab hmarey pass kuch aesy commands aor instructions set tool kit 

mai hian k jiss ko use kar k hum C mai apna pehla program likh sakty hian.

is ley aaj in cocept ko hum real program mai use karty hain.hum apny kuch chund

programs ka tayeen karty hain.jin ko pechy lessons mai diy gay topics ko parh kar 

easly solve kiya jasakey.

 

Jesa ka hum ney 

variables,constants ko dekha in ki different types ko parha.hum ney 

yeh bi dekha k in ko create kiss tarha kiya jata hai.

C++ in input output instructions ko use kiya.

Arithmeatic instructions,aor operator dekhy. 

 

aj in sub ko use kar k hum chund aik programs likty hain.

 

 

Program#1:

 

#include<iostream.h>

 

main()

{

    cout<<"Allah is One...........";

 

}

explanation:

dear student aik cheez note karney k qabil hai c k har program hai aik 

main function hota hai.jiss ko {main()} k andaaz sey likhty hian.

main() funciton k bad opening curly brace iss function ka hissa hia.

aor end per closing curly barce bi iss function ka hi hisaa hai. 

 

Main function:

1.agr kissi program mai main() funtion na hoo to compiler program mai error dey ga

2.main()function ki opention oar curly braces mi sey koi aik ya dono miss kar dey jay to 

  bi complier error dey ga.

3.C ka program sub sey pehly main() function sey hi run hona shuru hota hai.

4.main()funtion ki braces jo k iss waqt blank hai in ko prameters bi dey ja skty hian 

  lekin iss point ko abi note rakhy bad mai iss per tafseel sey behas ho gi

 

is main funtion() ka aik cout operator ki help sey screen per aik string "Allah is one.........."

print karwai gai hai.jo k iss program ka ask maqsad hai.

cout ki detial pechly lecture mai kafi detail sey byan ho chuky hai.

NOte:

C ki har statement k bad aik semicolon lazmi dalna chahly jo k asl mai compiler ko aik hadayt hai

k semicolon per aik instruction end ho gai hai.

 

Header file

#include<iostream.h>

mazkora line compiler ko aik header file program mai add karwany ki instruction hai.

header file k bary mai mazeed detial inshallah next any waly lectures mai detail k sath aye

gi abi k ley app sirf itna yad rakh ley k hmary program ko sahee tarha sey chalney k ley.iss file ko

add karwany ki zaroort thi.

 

yeh program to screen per aik line print karwata hai ab zra agay aey hum apni programing life ko kuch thora

sa difficulty ki tarf ley kar jaty hai. 

 

program#2:

oper waly program mai majood line ko hum differnt tareeqy sey print kar sakty hian. 

farz kary k hum ney oper waly line ko 3 lino mai print karna hai to us 

k ley hum ko aik aesy instruction ki zaroort hai jo k compiler ko yeh btay k kon sa word

kiss line per print karna hai aor kon sa word kiss line per print karna hai.

aye mai aik program likhta hoo jiss ko bad mai hum explain bi krty hai

 

#include<iostream.h>

main()

{

    cout<<Allah\n";

    cout<<"is\n";

    cout<<"one\n";

 

yeh program aor uper waly program mai farq sirf yeh hai k hum ney new line character use kiya hai.

(\n) ko new line character kehtey hain jo aik tarha sey compiler ko hdayat hai k jab bi yeh character cde mai aye

to compiler wha sey new line per cursur ko ley jata hai.

mai app ko chund special characters oar hian jin ka taruf karwana chahta hun 

 

 

\n cursur ko new line k shuru mai lany k ley use kiya jata hai.

\t cursur ko aik tab aagy ki tarf move karney k ley. use kiya jata hai.

\r cursur ko majooda line k start mai ley attta hai aor agr kuch likha jaye to usi line ko oer write karna shuru kar deta hai

\a system bell k ley hai iss ko use kary to system per aik beep ki awaaz aati hai.

\\ cursur ko aik character pechy ki tarf ley kar ata hai yani back space ka kam karta hai.

\" screen per agr " yeh symbol print karna hoo to us k le use  hota hai.

endl line ko khatm karney k ley. 

 

Note:

ab swal yeh peda hota hai k kiya koi aesa tareeqa hai k hum oper waly code mai 3 lines ki bjaey code mai aik line likh kar apna required reslut ley saky

to us ka jawab hai g hai hum yeh new line character ki maddad sey kar sakty hain. us ka tareeqa yeh hai.

cout<<"Allah\nis\none\n";

jesa k oper btaya ja chuka hai k \n character jha bi aye ga compiler wha sey new line start kar dey ga. 

 

program3:

2 integers ko sum karny k ley .

yeh program do numbers jo student keyboard sey enter kary ga us ko read kar k 2 different variables mai store karway ga.aor 

un ki values ko appss mai add karwa k aik or variable mai store kary ga jiss ko hum bad mai screen per print kar saky gy

 

#include <iostream>

 

using namespace std;

 

 

main()

{

   

    int var1=0;  /*declair a varible of type integer with name as var1 with                   starting value=0*/

    int var2=0;  /*declair a varible of type integer with name as var1 with starting value=0*/

    int var3=0;  /*declair a varible of type integer with name as var1 with starting value=0*/

    cout<<"Enter 1st number   \t";//prump user to enter a numbe

    cin>>var1;   //reads a number from keyboard and save to var1;

    cout<<"Enter 2nd number\t";

    cin>>var2;

    var3=var1 + var2; //add two numbers and store the result in var3

    cout<<"var3= \t"<<var3<<endl;//print the result on screen

        system("pause");  //pause executation for a while

 

}  

 

comments:

comments c program mai siway iss k aor koi hassiyat nahi rakhty k yeh users ki yaddasht k ley hian.compiler jab program ko 

compile karta hai to wo sub sey pehly program main sey comments ko utha kar bahir phank ta hai.

oar phir compilation shuru karta hai

comments likhney k do tareeq hain . 

// in 2 lines k agay jo bi ho wo comments hota hai iss ko single line comment style kehty hain

/*...*/ is pair k andr jo bi text ho wo bi comments hota hai. 

iss ko multyline comments style kehty hain. 

 

important point should be remembers

1. variables ka name self explainatry hona chahy yani yani variable ka name read kar k forn pta chal jana chahy k iss mai kiya cheez store ho rahy hain.

2. variables k names ko (_)sey start na kary however k yeh c main mna nahi hai.lekin achi prectus bi nahi hai

3. variables k C++ mai jiss jga marzi declair kar sakty hain ,C mai function k start mai hi karna hota hai.lekin achi prectus yeh k app functions k start mai hi variables ko define kar ley.

4. arithmetic operands k dono side mai aik aik space dey jiss sey code clear ho jata hai.

 

Assignment:

1.key board sey 3 numbers ki input ley in ka

   sum

   product

   caluale kar oar print karway 

2.Calculate the diameter and circumstance of a circle  by taking the value of its radius from user and use Pi=3.1415

3.screen per 9 ka table print karwany k ley aik program likhey

4.user sey 5 digiat ka aik number input ley phir us number ko reverse order mai print kary

  for example 

  orignal numer=12345

  numer in reverse order is=54321


--

Take your soul out of the way from cheristanity 
Asad Ali

BSc (Semester-02) 

City.Lahore


--
For study materials, past papers and assignments,
Join VU School at www.VusCool.com
and www.VUGuys.com
CoooL Virtual University Students Google Group.
To post to this group, send email to coool_vu_students@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/coool_vu_students?hl=en

No comments:

Post a Comment