Showing posts with label CS201. Show all posts
Showing posts with label CS201. Show all posts

Tuesday, November 22, 2011

CS201 Solved Midterm Paper


MIDTERM  EXAMINATION
Spring 2009 CS201- Introduction to Programming
Question No: 1      ( M a r k s: 1 ) http://vuzs.net_______
There are mainly------------------- types of software
►Two
►Three
►Four
►Five
Software is categorized into two main categories
o System Software
o Application Software
Question No: 2      ( M a r k s: 1 ) http://vuzs.net____
In C/C++ the #include is called,
<!--[if !vml]--><!--[endif]-->
►Header file
►Preprocessor Directive
►Statement
►Function
Question No: 3      ( M a r k s: 1 ) http://vuzs.net___________
&& is------------------ operator.
►An arithmetic
►Logical
►Relational
►Unary
we use logical operators ( && and || ) for AND and OR respectively with relational operators.
Question No: 4      ( M a r k s: 1 ) http://vuzs.net_______
In flow chart, the symbol used for decision making is,
►Rectangle
►Circle
►Arrow
►Diamond
Question No: 5      ( M a r k s: 1 ) http://vuzs.net______
The correct syntax of do-while loop is,
►(condition ) while; do { statements; };
►{ statements; } do-while ();
►while(condition); do { statements; };
►do { statements; } while (condition);
Question No: 6      ( M a r k s: 1 ) http://vuzs.net___________
C++ views each file as a sequential stream of________________ .
►Bytes
►Bits
►0’s or 1’s
►Words
Question No: 7      ( M a r k s: 1 ) http://vuzs.net__________________
If the elements of an array are already sorted then the useful search algorithm is,
►Linear search
►Binary search
►Quick search
►Random search
In binary search algorithm, the ‘divide and conquer’ strategy is  applied.
This plies only to sorted arrays in ascending or descending order.
Question No: 8      ( M a r k s: 1 ) http://vuzs.net___________
The address operator (&) can be used with,
►Statement
►Expression
►Variable
►Constant
Question No: 9      ( M a r k s: 1 ) http://vuzs.net_______________
When a pointer is incremented, it actually jumps the number of memory addresses
►According to data type
►1 byte exactly
►1 bit exactly
►A pointer variable can not be incremented
Question No: 10      ( M a r k s: 1 ) http://vuzs.net______________
Each pass through a loop is called a/an
►enumeration
►iteration
►culmination
►pass through
Question No: 11      ( M a r k s: 1 ) http://vuzs.net_____________
Call by reference mechanism should be used in a program when there is
i. large amount of data to be passed
ii. small amount of data to be passed
iii. need to change the passed data
iv. no need to change the passed data
Choose the appropriate option for the above case.
► (i) and (ii) only
►(i) and (iii) only
►(ii) and (iii) only
►(ii) and (iv) only
Question No: 12      ( M a r k s: 1 ) http://vuzs.net________
Which of the following is the starting index of an array in C++?
►0
►1
►-1
►any number
Question No: 13      ( M a r k s: 1 ) http://vuzs.net________
The return type of a function that do not return any value must be __________
►int
►void
►double
►float
Question No: 14      ( M a r k s: 1 ) http://vuzs.net_________
Which of the following is an extension of header file?
►.exe
►.txt
►.h
►.c
Question No: 15      ( M a r k s: 1 ) http://vuzs.net__________
We want to access array in random order which approach is better?
►Pointers
►Array index
►Both pointers and array index are better
►None of the given options.
Remember, if the array is to be accessed in random order, then the pointer approach may not be better than array indexing. (from handouts courtesy Omer Chaudhry )
Question No: 16      ( M a r k s: 1 ) http://vuzs.net____________
When we declare a multidimensional array the compiler store the elements of multidimensional array in the form of,
►Columns
►Rows
►Contiguous memory location
►Matrix
Question No: 17      ( M a r k s: 1 )__________
What is the output of the following program?
#include iostream.h
main ( ) {
int RollNo;
int rollno;
RollNo = 5;
rollno = 8;
cout << “Roll No is ” << rollno; }
Program should not compile due to missing from following statement
#include iostream.h
if we ignore this then output should be
Roll No is 8
Question No: 18      ( M a r k s: 1 )_____________________
Why we include iostream.h in our programs?
Because standard stream handling function are stored in this file. Before using these function in our program it is necessary to tell compiler about the location of these functions.
Question No: 19      ( M a r k s: 2 )
Find out error in the code given below:
if ( num % 2 = 0 )
cout << "The number is even" << endl;
if ( num % 2 = 0 ) There should be extra = sign following is right statement
if ( num % 2 = =0 )
Question No: 20      ( M a r k s: 3 )
How learning to design programs is like learning to play soccer?
“Learning to design programs is like learning to play soccer. A player must learn to trap a ball, to dribble with a ball, to pass, and to shoot a ball. Once the player knows those basic skills, the next goals are to learn to play a position, to play certain strategies, to choose among feasible strategies, and, on occasion, to create variations of a strategy because none fits. “
Question No: 21      ( M a r k s: 5 )
Write the procedure of data insertion in middle of the files by Merge Method practiced in older systems?
· Opened the data file and a new empty file.
· Started reading the data file from beginning of it.
· Kept on copying the read data into the new file until the location we want to insert data into is reached.
· Inserted (appended) new data in the new file.
· Skipped or jumped the data in the data file that is to be overwritten or replaced.
· Copied (appended) the remaining part of the file at the end of the new file
Question No: 22      ( M a r k s: 10 )
Write a recursive function that takes three arguments (an integer array, starting subscript ‘s’ and
ending subscript ‘e’ ).
In first recursive call, the function should display the array from subscript ‘s’ (s = 0) to ‘e’ (e =
size of array). In each successive call, the function should print the array from index s+1 to e. T
function should stop processing and return when starting subscript becomes equal to ending
subscript.
For example, if user enters values for array 2, 3, 4, 5, 6 then the recursive function must display the following output.
2 3 4 5 6
3 4 5 6
4 5 6
5 6
6
answer
#include ;
void PrintArray(int arrayInput[], int &s, int &e);
main ( )
{
int pause;
int TestArray [6] = {1,2,3,4,5,6};
int StartPoint = 0;
int EndPoint = 5;
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cout<<"\n";
PrintArray(TestArray , StartPoint, EndPoint);
cin >> pause;
}
void PrintArray(int arrayInput[], int& s, int& e)
{
for (int i = s; i<= e; i++)
{
cout<<  arrayInput[i];
}
s=s+1;
}

CS201 Solved Mcq,s



CS201- Introduction to Programming
CS201 Question No: 1      ( M a r k s: 1 )
In C/C++ the #include is called,
►Header file
►Preprocessor Directive
►Statement
►Function
cs201 Question No: 2      ( M a r k s: 1 )

To access the element of two dimensional array we use,


►Single referencing
►Single dereferencing
►Double dereferencing
►Double referencing
cs201 Question No: 3      ( M a r k s: 1 )
Data Size of the file is always___________ the actual size of the file.
►Greater than
►Equal to
►Less than or equal to
►None of the above
cs201 Question No: 4      ( M a r k s: 1 )
When an identifier is declared with keyword const then,
►Its value can be changed during execution.
►Its value can not be changed
►Its value can be changed with arithmetic operator
►Its value can be overwritten
cs201 Question No: 5      ( M a r k s: 1 )
In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of this array will be stored at,
►Arr[0]
►Arr[8]
►Arr[7]
►Arr[-1]


cs201 Question No: 6      ( M a r k s: 1 )
If it is required to copy an array to another array then,
►Both arrays must be of the same size and data type
►Both arrays may be of different size
►Both arrays may be of different data type
►Both arrays may be of different size and type
cs201 Question No: 7      ( M a r k s: 1 )
In C/C++ all character strings are terminated with,
► Null character
► String
► Zero
► Full stop
cs201 Question No: 8      ( M a r k s: 1 )
Let suppose

struct intorDouble {
int ival; Double charvar;
};
  main(){
   intorDouble VAZ;
          int size ;
  size =             sizeof(VAZ);
}
What will be the value of variable size, if int occupies 4 bytes and double occupies 8 bytes?
► 2
► 4
► 8
► 12
cs201 Question No: 9      ( M a r k s: 1 )
When a pointer is incremented, it actually jumps the number of memoryaddresses
►According to data type
►1 byte exactly
►1 bit exactly
►A pointer variable can not be incremented
cs201 Question No: 10      ( M a r k s: 1 )
Do-while loop executes at least,



►Zero Time
►One Time
►Two Times
►N Times
cs201 Question No: 11      ( M a r k s: 1 )
+= , *= , /= , etc are called,
►Assignment operators
►Logical operator
►Compound assignment operator
►Unary operator
cs201 Question No: 12      ( M a r k s: 1 )
Computer can understand only machine language code.
►True
►False
cs201 Question No: 13      ( M a r k s: 1 )

Which of the following is the correct syntax to print multiple values or variables in a single command using cout?
►cout <

Wednesday, November 2, 2011

CS201 Assignment(1) Solution

CS201 Assignment(1) Solution

#include <iostream>
using namespace std;
main()
{ 
      int customer_nos,Grand_total;
      char choice;
      customer_nos=0;
      Grand_total=0;
          
do{
int meal,sale_tax;
cout<<"Virtual Resutrant\n";
 cout<<"\nenter the price of meal: " ;
cin>>meal;
//sale tex caluculate

 if (meal < 1000)
    {
         sale_tax=0 ;
          cout<< "Sale Tax = "<<sale_tax<<endl;

          }
else if (meal > 1000 && meal <=2000)
    {
        sale_tax= (meal/100)*1;
          cout<< "Sale Tax = " <<sale_tax<<endl;
         
          }
else
    {
        sale_tax= (meal/100)*2;
          cout<< "Sale Tax = " <<sale_tax<<endl;
         
          }

//total amount calc

int total_amount;
total_amount=meal+sale_tax;
cout<<"---------------------------------------";
cout<<"\ntotal amount is "<<total_amount<<endl;

//swet dish

if (total_amount <1000)
{
             cout<<"\nCustomer deserve Candies";   
                
                 }
else if (total_amount >=1000 && total_amount <2000)
{
             cout<<"\nCustomer deserve Sweet bread";   
                
                 }
                
else if (total_amount >=2000 && total_amount <3000)
{
             cout<<"\nCustomer deserve pudding";   
                
                 }                
                

else if (total_amount >=3000 && total_amount <4000)
{
             cout<<"\nCustomer deserve cake";   
                
                 }                            
else
{
             cout<<"\nCustomer deserve trifle";   
                
                 }                     
                
cout<< "\nDo you want to proces another coustomer ";

cin>>choice;
customer_nos++;
Grand_total=Grand_total+total_amount;
}while (choice=='Y' || choice=='y');


cout<<"\n\nNumber of Customer is "<<customer_nos;
cout<<"\nGradn Total is "<<Grand_total<<endl;

system("pause");
}

Monday, July 4, 2011

CS201 Final Term Past Solved Paper 6


FINALTERM EXAMINATION
Spring 2010 CS201- Introduction to Programming
If it is required to copy an array to another array then,
 ► Both arrays must be of the same size and data type  ► Both arrays may be of different size    ► Both arrays may be of different data type
 ► Both arrays may be of different size and type

Dealing with structures and functions passing by reference is the most economical method
 ► True  ► False


eof( ), bad( ), good( ), clear( ) all are manipulators.
 ► True      ► False

 Overloaded new operator function takes parameter of type size_t and returns
 ► void (nothing)   ► void pointer
 ► object pointer    ► int pointer
   
When new operator is overloaded at global level then corresponding built-in new operator will not be visible to whole of the program.
 ► True         ► False

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?
 ► parentheses ( )  ► braces { }  ► brackets [ ]  ► arrows < >

The return type of a function that do not return any value must be ________
 ► float   ► int   ► void   ► double
 
UNIX has been developed in ________ language.
 ► JAVA   ► B  ► C   ► FORTRAN

Like member functions, ______ can also access the private data members of a class.

► Non-member function ► Friend functions ► Any function outside class ► None of the given options

Which of the following statement is best regarding declaration of friend function?
► Friend function must be declared after public keyword.
► Friend function must be declared after private keyword.
► Friend function must be declared at the top within class definition.
► It can be declared anywhere in class as these are not affected by the public and private keywords.

The operator function overloaded for an Assignment operator (=) must be
► Non-member function of class ► Member function of class
► Friend function of class  ► None of the given options

The endl and flush are _______
 ► Functions ► Operators ► Manipulators  ► Objects

If a symbolic constant has been defined, it will be an error to define it again.
 ► True    ► False 

The operator used for casting, in C, is standard ________ operator.
 ► none of the given options. ► cast   ► cost   ► const

Constructors can not be overloaded like ordinary functions.
 ► True   ► False 

Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = ‘*’ );
► defaultParameters (5);  ► defaultParameters (5, ‘8’);
► defaultParameters (6, ‘#’);  ► defaultParameters (0, 0, ‘*’, 0);

 When an operator function is defined as member function for a binary Plus (+) operator then the number of argument it take is/are.
► Zero  ► One ► Two  ► N arguments

Wecan not define a variable of user-defined data type in the class.
► True     ► False

When an object of a class is defined inside an other class then,
 ► Constructor of enclosing class will be called first
 ► Constructor of inner object will be called first
 ► Constructor and Destructor will be called simultaneously
► None of the given options

The appropriate data type to store the number of rows and colums of the matrix is____________.
► float  ► int   ► char  ► none of the given options.

Class is a user defined___________.
 ► data type  ► memory referee  ► value  ► none of the given options.

A class is a user defined data type

Question No: 22      ( Marks: 1 ) - Please choose one


 A pointer variable can be,

       ► Decremented

       ► Incremented

       ► Multiplied

       ► Both Decremented and Decremented


Question No: 23      ( Marks: 1 ) - Please choose one


NULL value has been defined in ______ and _________ header files.


       ► strings.h and iostream.h


       ► ctype.h and conio.c


       ► conio.c and conio.h


       ► stdlib.h and stddef.h


NULL has been defined in the header files stdlib.h and stddef.h.

Question No: 24      ( Marks: 1 ) - Please choose one


A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this , _______________

       ► Write a separate class to handle each

       ► Use templates

       ► Use strings to store all types

       ► None of the given options


Question No: 25      ( Marks: 1 ) - Please choose one


"setprecision" manipulator will set

       ► The number of digits after the decimal point

       ► The number of digits before the decimal point

       ► The number of digits in a number

       ► None of the given options

setprecision. This is the parameterized, inline- manipulator that sets the places after the decimal point.

Question No: 26      ( Marks: 1 ) - Please choose one


Which of the following option will be true, if we overload "-=" operator?


       ► only - operator needs to be overloaded (not sure)

       ► Minus (-) and = operators need to be overloaded

       ► the -= operator need to be overloaded explicitly

       ► the - and = operators need to be overloaded implicitly 

 
Question No: 27      ( Marks: 2 )


Suppose there is a template function ‘func’ having argument of type U and return type T. What will be the C++ syntax to call this function, passing a variable ‘x’ of type double and returning an int type?


Question No: 28      ( Marks: 2 )


Which variable will be used in inner code block if we have the same names of variable at outer code block and inner code block?



Question No: 29      ( Marks: 2 )


What is the benefit of reference and where can we use it?



Question No: 30      ( Marks: 2 )


Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for the object d of type Date.



Question No: 31      ( Marks: 3 )


What will be the output of following functions if we call these functions three times?

1)
void func1(){
int x = 0;
x++;
cout << x << endl;
}
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
} 


 
Question No: 32      ( Marks: 3 )


If the requested memory is not available in the system then what does calloc/malloc and new operator return?



Question No: 33      ( Marks: 3 )


Suppose an object of class A is declared as data member of class B.
(i) The constructor of which class will be called first?
(ii) The destructor of which class will be called first?


Question No: 34      ( Marks: 5 )


What is difference between Unary and binary operators and how they can be overloaded?



Question No: 35      ( Marks: 5 )


Suppose we have the following class.

class Matrix
{
private:
int Elements[3][3];
};

Write the operator function of stream extraction operator (>>) for this class.



Question No: 36      ( Marks: 5 )


What is meant by user interface and class interface in C++ ? And what role a class interface can play in user interface [Marks 5]

Contact Form

Name

Email *

Message *