Thursday 9 May 2013

QUIZ ANSWERS 11-15

QUIZ ANSWERS 11-15

11.
A function that returns no values to the program that calls it is _____
not allowed in C++
type void
type empty
type barren
Answer: Option B


12. 
The keyword used to define a structure is _____
Stru
stt
Struct
structure
Answer: Option C

13. 
Which of the following statements is false?
A function is a block of code that performs a specific task
Functions allow programmers to break large and complex problems into small and manageable tasks
Functions allow programmers to use existing code to perform common tasks
Functions can be called, or invoked, only once in a program
Programmer-defined functions can be either value-returning or void
Answer: Option D

14. 
Header files often have the file extension _____
.H
.HE
.HEA
.HEAD
Answer: Option A

15. 
The #ifndef directive tests to see whether ________
a class has been defined
a variable has been given a value
a class has no variable definitions
any objects of the class have been instantiated
Answer: Option A

#ifndef checks whether the given token has been #defined earlier in the file or in an included file; if not, it includes the code between it and the closing #else or, if no #else is present, #endif statement#ifndef is often used to make header files idempotent by defining a token once the file has been included and checking that the token was not set at the top of that file.

Sorting a given list of numbers in ascending order.


Sorting a given list of numbers in ascending order.

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int x[20],n;

cout<<"How many Numbers you want to enter:";
cin>>n;

cout<<"\nEnter Values:";
for(int i=0;i<n;i++)
cin>>x[i];

int temp;
for(int i=0;i<n-1;i++) // for controling passes
{
for(int j=0;j<n-1;j++) // for making comparisons
{
if(x[j]>x[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
cout<<"\nSorted Elements in ascending order:\n";

for(int k=0;k<n;k++) // for printing numbers
cout<<x[k]<<"\t";

getch();
}