..# Function #..
Easy P.217 /2
Write the C++ code for a void function that
prompts the user to enter the name of an item, and than stores the user’s
response in the String variable whose address is passed to the function.
Name the function getItemName().
Answer void getItemName(){
}
Answer void getItemName(){
}
Middle
P.166 /1
Write the C++ code for a function that receives
an integer passed to it. The function, name halveNumber() , should
divide the integer by 2, and than return the result (which may contain a
decimal place.)
Answer void setup(){ //สร้างฟังก์ชัน เพื่อทดลองการปริ๊นค่า
println(halveNumber(20)); // ปริ๊นค่า ฟังก์ชัน halveNumber เมื่อให้ค่า x = 20;
}
float halveNumber( int x ){ // สร้างฟังก์ชันที่ส่งค่ากลับได้ชื่อ halveNumber
return x/2; // divide the integer by 2 and than return the result
}
Answer void setup(){ //สร้างฟังก์ชัน เพื่อทดลองการปริ๊นค่า
println(halveNumber(20)); // ปริ๊นค่า ฟังก์ชัน halveNumber เมื่อให้ค่า x = 20;
}
float halveNumber( int x ){ // สร้างฟังก์ชันที่ส่งค่ากลับได้ชื่อ halveNumber
return x/2; // divide the integer by 2 and than return the result
}
Hard
P.217 /4
Write the C++ cord for a void function that
receives three double variable: the first two by value and the
last one by reference. The function should divide the first variable by
the second variable, and than store the result in the third variable. Name the
function quotient().
ไม่มีความคิดเห็น:
แสดงความคิดเห็น