Question: 12) True or false for following statements? 1) Both Java and C are object oriented programming languages. 2) C++, C# and Java are all descendants
12) True or false for following statements?
1) Both Java and C are object oriented programming languages.
2) C++, C# and Java are all descendants of C.
3) Both Java and C can use a character from the Unicode character set..
4) The following while statement in C will never terminate.
i = 1;
while ( i != 1000 ) {
if ( i % 2 == 0 )
{ i = i + 2; }
else { i = i - 1; } }
5) If you want to execute the loop for N times, then set the counter to 0 and include the test counter < N.
6) The following while statement in C will never terminate.
i = 1;
while ( i =1 ) {
i++;
}
13) The quotes are very tricky in Unix Shell. Please describe the differences among double quote " , single quote ' and grave accent ` .
14) To access the value of one variable, what special symbol we should use before the name of variable? And what do $1 and $2 mean in shell script? What variable can be used when we want to get all the arguments on command? What variable contains the return value of last command?
15) Write the output for following shell script and C statement.
1) Assume the current working directory is home directory, which contains two files HW3.pdf and q1.sh.
The content in q1.sh is displayed below:
if [ -e ~/HW3.pdf ]
then
echo The full path of HW3.pdf is `pwd`
else
echo HW3 does not exist in current directory.
fi
What will be the output after executing following command? $./q1.sh
2) The content in q2.sh is displayed below:
#!/bin/sh
res=0
x=0
# check command line
if [ $# -lt 2 ] ; then
echo "Oops! I need atleast 2 command line args"
echo "Syntax: $0: number1 number2 ... numberN"
echo "Example:$0 56 66 34"
exit 1
fi
for i in $@
do
x=`expr $x + $i `
done
res=`expr $x / $# `
echo "res = $res"
What will be the output after executing following command? $./q2.sh 3
3)Continue on question 2)
What will be the output after executing following command? $./q2.sh 12 4 8 Output:
4) The function of this program?
(a) Calculate the average of numbers given in command line.
(b) Calculate the average of numbers given in command line.
(c) Calculate the multiplication of numbers given in command line.
(d) None of above. Part VI: Writing programs
1) Write a Bourne Shell script named as "prime.sh" to check if a number is a prime or not. The number is from user's input.
$./prime.sh
Enter a number : 10
The number 10 is not a prime
$./prime.sh
Enter a number : 3
The number 3 is a prime
2) Write a C program named as "prime.c" to finish the same task.
$cc -o prime prime.c
$./prime
Enter a number : 10
The number 10 is not a prime
$./prime
Enter a number : 3
The number 3 is a prime
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
