Laboratory Work №2 Theme: Implementation of functions, parameters and data transfer Aim



Download 263,25 Kb.
bet1/4
Sana01.01.2022
Hajmi263,25 Kb.
#293403
  1   2   3   4
Bog'liq
DSA Lab2
download, Tanllov asosida qabul, Nemis, Ёдгоров А.А. 235753ee3e0dd438c4bb364d5fa70163, Murakkab songa bo’linish alomatlari, Россия, 9ns, statistika, statistika, Фалсафа 8-Мавзу, KURS ISHIJUMANIYOZOV, 2-lab{Abdumajidov Abdurrahmon}, y2dXxDghRmnRRzdMrwSv46atf7QaRU5T, 195 1903 Qadimgi To, 7777

Laboratory Work 2

Theme: Implementation of functions, parameters and data transfer

Aim: Developing skills in programming semi-static data structures.

In general, we can hide the details of any computation by defining a function. A function definition requires a name, a group of parameters, a return type, and a body. It may either return a variable, value, or nothing (specified by the keyword void). For example, the simple function defined below returns an integer which is the double of the value you pass into it.

#include

using namespace std;


int timesTwo(int num) {

/* return type int which indicates

that an integer is being returned */

return num*2;

}
int main() {

/* return type int which indicates that

an integer is being returned */

cout<
return 0;

}


The syntax for this function definition includes the name, timesTwo, and a parenthesized list of formal parameters and their types. For this function an int named num is the only formal parameter, which suggests that timesTwo needs only one piece of data to do its work. The details, hidden “inside the box,” simply compute the result of num*2 and return it. We can invoke or call the timesTwo function by asking the C++ to evaluate it, passing an actual parameter value, in this case, 3. Note that the call to timesTwo returns an integer that can in turn be passed to another invocation.

Let us look at a similar function.



Implementation of the timesTwoVoid function:

#include

using namespace std;
void timesTwoVoid(int num) {

/* return type void which indicates

that an nothing is being returned */

cout<< num*2<

}
int main() {

/* return type int which indicates that

an integer is being returned */

timesTwoVoid(5);


return 0;

}

Take a look at the code below:



#include

using namespace std;


void dogWalk(int steps){

Download 263,25 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2022
ma'muriyatiga murojaat qiling

    Bosh sahifa
davlat universiteti
ta’lim vazirligi
axborot texnologiyalari
maxsus ta’lim
zbekiston respublikasi
guruh talabasi
O’zbekiston respublikasi
nomidagi toshkent
o’rta maxsus
davlat pedagogika
texnologiyalari universiteti
toshkent axborot
xorazmiy nomidagi
rivojlantirish vazirligi
pedagogika instituti
Ўзбекистон республикаси
tashkil etish
haqida tushuncha
таълим вазирлиги
vazirligi muhammad
O'zbekiston respublikasi
toshkent davlat
махсус таълим
respublikasi axborot
kommunikatsiyalarini rivojlantirish
vazirligi toshkent
saqlash vazirligi
fanidan tayyorlagan
bilan ishlash
Toshkent davlat
sog'liqni saqlash
uzbekistan coronavirus
respublikasi sog'liqni
coronavirus covid
koronavirus covid
vazirligi koronavirus
qarshi emlanganlik
risida sertifikat
covid vaccination
sertifikat ministry
vaccination certificate
Ishdan maqsad
fanidan mustaqil
matematika fakulteti
o’rta ta’lim
haqida umumiy
fanlar fakulteti
pedagogika universiteti
ishlab chiqarish
moliya instituti
fanining predmeti