Solved CS201 Intro To Programing
Solved CS201 Intro To Programing
Solved CS201 Intro To Programing
► Sequential File
► Data File
► Record File
► #error
► #define
► #line
► #ndefine
Question No: 3 ( Marks: 1 ) - Please choose one
► True
► False
► True
► False
► void (nothing)
► void pointer
► object pointer
► int pointer
► True
► False
► True
► False
► #include “iostream.h”
► include <iostream.h>
► include <iostream.h>
► #include <iostream.h>
► True
► False
Question No: 12 ( Marks: 1 ) - Please choose one
Template class can not have static variables.
► True
► False
What will be the correct syntax to assign an array named arr of 5 elements to a pointer
ptr?
► *ptr = arr ;
► ptr = arr ;
► *ptr = arr[5] ;
► ptr = arr[5] ;
What will be the correct syntax to access the value of fourth element of an array using
pointer ptr?
► ptr[3]
► (ptr+3)
► *(ptr+3)
► Both 1and 3
► True
► False
► True
► False
► function prototype
► function definition
► looped
► nested
► overloaded
► Data encapsulation
► Constructor
► Destructor
► Compile Time
► Run Time
► Link Time
► True
► False
► Class, Objects
► Structures, Pointers
► None of above
► True
► False
Ans:
The manipulators are like something that can be inserted into stream, effecting a change
in the behavior. For example, if we have a floating point number, say pi (л), and have
written it as float pi = 3.1415926 ; Now there is need of printing the value of pi up to two
decimal places i.e. 3.14 . This is a formatting functionality. For this, we have a
manipulator that tells about width and number of decimal points of a number being
printed.
Some manipulators are parameter less. We simply use the name of the manipulator that
works. For example, we have been using endl, which is actually a manipulator, not data.
When we write cout << endl ; a new line is output besides flushing the buffer. Actually,
it manipulates the output stream.
Ans:
1) Matrix m1 (m2); copy constructor
2) Matrix m1, m2;
m1 = m2; assignment operator
3) Matrix m1 = m2; assignment operator
Ans:
1/5
Question No: 33 ( Marks: 3 )
Identify the errors in the following member operator function and also correct
them.
math * operator(math m);
}
ANS:
The errors are in the arguments of the member operation function and also in the body of
operator member function.
Ans:
#include <iostream>
#include <iomanip>
int main ()
{
double x1 = 12345624.72345
double x2 = 987654.12345
double x3 = 1985.23456
cout << setprecision (3) << x1<< endl;
cout << setprecision (4) << x2 << endl;
cout << setprecision (5) << x3<< endl;
return 0;
}
Ans:
Many thing can be possible without using templates but it do offer several clear
advantages not offered by any other techniques:
Advanatages:
• Templates are easier to write than writing several versions of your similar code for
different types. You create only one generic version of your class or function instead of
manually creating specializations.
• Templates are type-safe. This is because the types that templates act upon are known at
compile time, so the compiler can perform type checking before errors occur.
• Templates can be easier to understand, since they can provide a straightforward way of
abstracting type information.
• It help in utilizing compiler optimizations to the extreme. Then of course there is room
for misuse of the templates. On one hand they provide an excellent mechanism to create
specific type-safe classes from a generic definition with little overhead.
Disadvantages:
On the other hand, if misused
• Templates can make code difficult to read and follow depending upon coding style.
• They can present seriously confusing syntactical problems esp. when the code is large
and spread over several header and source files.
• Then, there are times, when templates can "excellently" produce nearly meaningless
compiler errors thus requiring extra care to enforce syntactical and other design
constraints. A common mistake is the angle bracket problem.
}
}
……………………………………………………………………………
FINALTERM EXAMINATION
Fall 2008
CS201- Introduction to Programming
Time: 120 min Marks: 75
Answer: The default value of a parameter is provided inside the function prototype or
function definition. For example, we could declare the default function arguments for a
function while declaring or defining it.
Question No: 32 ( Marks: 1 )
Why do java consider pointer as dangerous
Answer:
The concept of pointers is very important but quite limited to C and C++. The modern
languages, for example JAVA, describe pointers as dangerous. We can go anywhere in
the memory and can change a value. There is another problem with pointers, which is
that these could be pointing to nowhere.
Do you think that friend functions violate encapsulation? Justify your answer.
Answer:
The friend functions of a class have access to the private data members of class. Despite
being a good thing, there is possibility of vulnerability. We are opening our thoughts,
inside view for somebody else. Without having 100% trust, it will be risky to make our
thoughts and feelings public. We want that our private data is accessible to someone
outside, not public for everybody. Otherwise, the data encapsulation and data-hiding
concept will be violated. We keep the data members private and declare some specific
functions that are not member of the class but friend of the class. As friends, they have
access to the inside data structure of the class despite not being members.
Write a simple program using the get() member function of cin object reading a text of
30 characters from the keyboard, store them in an array and then using put() member
function of cout object to display them on the screen.
Write a small program which defines two user-defined manipulators named octal
and hexadecimal. These manipulators should display the decimal numbers into octal and
hexadecimal.
In the main function, input a decimal number from the user and then display this
decimal number into octal and hexadecimal using user-define manipulators named octal
and hexadecimal.
► Sequential File
► Data File
► Record File
► #error
► #define
► #line
► #ndefine
► True
► False
► True
► False
► void (nothing)
► void pointer
► object pointer
► int pointer
The second parameter of operator functions for << and >> are objects of the class for
which we are overloading these operators.
► True
► False
► True
► False
► #include “iostream.h”
► include <iostream.h>
► include <iostream.h>
► #include <iostream.h>
► True
► False
► True
► False
What will be the correct syntax to assign an array named arr of 5 elements to a pointer
ptr?
► *ptr = arr ;
► ptr = arr ;
► *ptr = arr[5] ;
► ptr = arr[5] ;
What will be the correct syntax to access the value of fourth element of an array using
pointer ptr?
► ptr[3]
► (ptr+3)
► *(ptr+3)
► Both 1and 3
► True
► False
► True
► False
► function prototype
► function definition
► looped
► nested
► overloaded
► Data encapsulation
► Constructor
► Destructor
► Compile Time
► Run Time
► Link Time
► True
► False
► Class, Objects
► Structures, Pointers
► None of above
► True
► False
Ans:
The manipulators are like something that can be inserted into stream, effecting a change
in the behavior. For example, if we have a floating point number, say pi (л), and have
written it as float pi = 3.1415926 ; Now there is need of printing the value of pi up to two
decimal places i.e. 3.14 . This is a formatting functionality. For this, we have a
manipulator that tells about width and number of decimal points of a number being
printed.
Some manipulators are parameter less. We simply use the name of the manipulator that
works. For example, we have been using endl, which is actually a manipulator, not data.
When we write cout << endl ; a new line is output besides flushing the buffer. Actually,
it manipulates the output stream.
Ans:
1) Matrix m1 (m2); copy constructor
2) Matrix m1, m2;
m1 = m2; assignment operator
3) Matrix m1 = m2; assignment operator
Ans:
1/5
}
ANS:
The errors are in the arguments of the member operation function and also in the body of
operator member function.
Ans:
#include <iostream>
#include <iomanip>
int main ()
{
double x1 = 12345624.72345
double x2 = 987654.12345
double x3 = 1985.23456
cout << setprecision (3) << x1<< endl;
cout << setprecision (4) << x2 << endl;
cout << setprecision (5) << x3<< endl;
return 0;
}
Ans:
Many thing can be possible without using templates but it do offer several clear
advantages not offered by any other techniques:
Advanatages:
• Templates are easier to write than writing several versions of your similar code for
different types. You create only one generic version of your class or function instead of
manually creating specializations.
• Templates are type-safe. This is because the types that templates act upon are known at
compile time, so the compiler can perform type checking before errors occur.
• Templates can be easier to understand, since they can provide a straightforward way of
abstracting type information.
• It help in utilizing compiler optimizations to the extreme. Then of course there is room
for misuse of the templates. On one hand they provide an excellent mechanism to create
specific type-safe classes from a generic definition with little overhead.
On the other hand, if misused
• Templates can make code difficult to read and follow depending upon coding style.
• They can present seriously confusing syntactical problems esp. when the code is large
and spread over several header and source files.
• Then, there are times, when templates can "excellently" produce nearly meaningless
compiler errors thus requiring extra care to enforce syntactical and other design
constraints. A common mistake is the angle bracket problem.
}
}
……………………………………………………………………………