+92 307 4151718 vuassassins@gmail.com




CS201 – Introduction to Programming

In CS201 Introduction to Programming. It is also known as coding and it’s also process in encoding & algorithm. The course which is used C++ Integrated Development Environment (IDE). When develop an application the programming language is semantic and syntax. We have covered digitized mid and final paper, video, notes, chapter wise Quiz preparation. It’s mobile compatible site. You can prepare your exams on your mobile.

NOTE: Click on Preparation Tab to take the Quiz Tests.

MID TERM

CS201_Mid_2008_Papers1                                                               View     Download

CS201_Mid_2010_MCQS_Papers5                                                  View     Download

CS201_Mid_Fall_Moaaz_Papers3                                                    View     Download

CS201_Mid_Fall_Paper2                                                                   View     Download

CS201_Mid_Fall_Sbj_Moaaz_Papers4                                             View     Download

 

FINAL TERM

CS201_Final_curentsubjectivesolved                                              View     Download

CS201_Final_Spring20093SolReference                                         View     Download

CS201_Final_SubjectiveQuestions                                                  View     Download

CS201_Final_SubjectiveQuestions01                                              View     Download

CS201_Final_SubjectiveQuestions2                                                View     Download

CS201_FinalsolmcqsbyMoaazandAsad                                           View     Download

CS201_FinalTermPaper3                                                                 View     Download

CS201_FinalTermPapers8                                                               View     Download

CS201_FinalTermPapers9                                                               View     Download

CS201_FinalTermPapers12                                                             View     Download

CS201_FinalTermPapers13                                                             View     Download

MID CHAPTER WISE PREPARATION BY JAHAN ZAIB ASHIQ

CS201 – Mid Chapter Wise Quiz 01 to 04

CS201 – Mid Chapter Wise Quiz 05 to 06

CS201 – Mid Chapter Wise Quiz 07 to 08

CS201 – Mid Chapter Wise Quiz 09 to 10

CS201 – Mid Chapter Wise Quiz 11 to 14

CS201 – Mid Chapter Wise Quiz 15 to 17

CS201 – Mid Chapter Wise Quiz 18 to 20

CS201 – Mid Chapter Wise Quiz 21 to 23

FINAL CHAPTER WISE PREPARATION BY JAHAN ZAIB ASHIQ

CS201 – Final Chapter Wise Quiz 23 to 26

CS201 – Final Chapter Wise Quiz 27 to 30

CS201 – Final Chapter Wise Quiz 31 to 35

CS201 – Final Chapter Wise Quiz 36 to 39

CS201 – Final Chapter Wise Quiz 40 to 45

POSTED DATE:25-01-2019

#include<iostream>
#include<string.h>
using namespace std;
class personalPassword{//class starts
private:
char password[10];
char* passptr;
public:
personalPassword(){//default constructor
strcpy(password, “Null”);
passptr = password;
cout << “……The default constructor called……\n\n”;
cout << “The default value of password is: “<< password <<endl;
cout << “The default value of password pointer is: “<< passptr <<“\n\n”;
}
void setPass(){
cout << “Please enter the password:”;
cin >> password;
}
char* getPass() const{
return passptr;
}
void passEncrypt(){
char key = ‘k’;
for(int i=0; i<strlen(password); i++)
password[i] = password[i] ^ key;
cout << “The encrypted password using the passEncrypt() function is: “<<password<<endl;
}
void passDcrypt(){
char key = ‘k’;
for(int i=0; i<strlen(password); i++)
password[i] = password[i] ^ key;
cout << “The decrypted password using the passDcrypt() function is: “<<password<<endl;
}
};//class ends
int main()
{
personalPassword pass;//pass is an object of type personalPassword
pass.setPass();
cout << “The password via getter function is: “<<pass.getPass()<<endl;
pass.passEncrypt();
pass.passDcrypt();
return 0;
}

CS201- Introduction to Programming – Quiz 1

 

CS201- Introduction to Programming – Quiz 2

 

CS201- Introduction to Programming – Quiz 3

 

CS201- Introduction to Programming – Quiz 4

 

CS201- Introduction to Programming – Quiz 5

 

CS201- Introduction to Programming – Quiz 6

 

VIVA FILE

CS201_Final_Viva File                     View     Download                    OR

What is C++?
C++ is created by Bjarne Stroustrup of AT&T Bell Labs as an extension of C, C++ is an object-oriented computer language used in the development of enterprise and commercial applications. Microsoft’s Visual C++ became the premier language of choice among developers and programmers.

What are the basic concepts of object oriented programming?
It is necessary to understand some of the concepts used extensively in object oriented programming.These include
§  Objects
§  Classes
§  Data abstraction and encapsulation
§  Inheritance
§  Polymorphism
§  Dynamic Binding
§  Message passing

Define inheritance?
The mechanism of deriving a new class (derived) from an old class (base class) is called inheritance. It allows the extension and reuse of existing code without having to rewrite the code from scratch. Inheritance is the process by which objects of one class acquire properties of objects of another class.

Define Polymorphism?
Polymorphism means one name, multiple forms. It allows us to have more than one function with the same name in a program.It allows us to have overloading of operators so that an operation can exhibit different behaviors in different instances.

What are the features of C++ different from C?
§  All the features of C are similar to C++ except some features, such as polymorphism, operator overloading which are supported in C++ but not in C language.
§  Both C and C++ language is similar in their functionality but C++ provides with more tools and options.

What is encapsulation?
The wrapping up of data and functions into a single unit (called class) is known as encapsulation. Encapsulation containing and hiding information about an object, such as internal data structures and code.

What is message passing?
An object oriented program consists of a set of objects that communicate with each other. Message passing involves specifying the name of the object, the name of the function and the information to be sent.

What are tokens in C++?
The smallest individual units of a program is known as tokens. c++ has the following tokens :
§  Keywords
§  Identifiers
§  Constants
§  Strings
§  Operators

What is the use of enumerated data type? 
An enumerated data type is another user defined type which provides a way for attaching names to numbers thereby increasing comprehensibility of the code. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2, and so on.

What is the use of default constructor?
A constructors that accepts no parameters is called the default constructor.If no user-defined constructor exists for a class A and one is needed, the compiler implicitly declares a default parameter-less constructor A::A(). This constructor is an inline public member of its class. The compiler will implicitly define A::A() when the compiler uses this constructor to create an object of type A. The constructor will have no constructor initializer and a null body.

Define Constructors?
A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created.It is called constructor because it constructs the values of data members of the class.

How variable declaration in c++ differs that in c?
C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use.

Define destuctors?
§  A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
§  A destructor as the name implies is used to destroy the objects that have been created by a constructors.
§  Like a constructor , the destructor is a member function whose name is the same as the class name but is preceded by a tilde.

What is a class?
A class is a collection of objects.

What is the difference between c & c++?

  • C++ is an object oriented programing but C is a procedure oriented programing.
  • C is super set of C++.
  • C can’t support inheritance, function overloading, method overloading etc. but c++ can do this.
  • In c program the main function could not return a value but in the c++ the main function should return a value.

What are the few advantages of Inline function?
§  It offers an improved macro facility.
§  By using the inline functions, the user can split a large function with many nested modules of statement blocks into many small inline functions.

What is copy constructor?
Copy constructor is a constructor function with the same name as the class and used to make deep copy of objects.

What is default constructor?
A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.

What is a scope resolution operator?
The scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

What is the difference between Object and Instance?
§  An instance of a user-defined type is called an object. We can instantiate many objects from one class.
§  An object is an instance of a class.

What is the difference between macro and inline?
Inline follows strict parameter type checking, macros do not.
Macros are always expanded by preprocessor, whereas compiler may or may not replace the inline definitions.

How variable declaration in c++ differs that in c?
C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use.

What is multiple inheritance?
A class can inherit properties from more than one class which is known as multiple inheritance.

what is the use of virtual destructor in c++?
§  A destructor is automatically called when the object is destroyed.
§  A virtual destructor in C++ is used primarily to prevent resource leaks by performing a clean-up of the object.

What do you mean by reference variable in c++?
A reference variable provides an alias to a previously defined variable.
Data -type & reference-name = variable name

What is iterator class?
§  Iterator class provides an access to the class which are inside the containers(it holds a group of objects in an organized way).
§  The containers include the data structure, class and abstract data type.

What are the types of declarations in C++?
There are so many types of declaration in C++ are :
§  Variable declaration
§  Constant declaration
§  Function declaration
§  Object declaration

What are Smart pointers?
Smart pointers are almost similar to pointers with additional features such as automatic destruction of a variable when it becomes out of scope and the throwing of exceptions that ensures the proper destruction of the dynamically allocated objects.

Explain function template?
Function template provides a means to write generic functions for different data types such as integer, long, float or user defined objects.

Explain class template?
Class template provides a means to write a generic class for different types so that a class can have members based on generic types that do not need to be defined at the moment of creating the class or whose members use these generic types.

What is difference between function overloading and operator overloading?
A function is overloaded when same name is given to different function.
While overloading a function, the return type of the functions need to be the same.

What are the advantages of inheritance?
§  Code re-usability
§  Saves time in program development.

What is a dynamic constructor?
§  The constructor can also be used to allocate memory while creating objects.
§  Allocation of memory to objects at the time of their construction is known as dynamic construction of objects.
§  The memory is allocated with the help of the new operator.

What is the difference between an Array and a List?
The main difference between an array and a list is how they internally store the data. whereas Array is collection of homogeneous elements. List is collection of heterogeneous elements.

What is the use of ‘using’ declaration?
A using declaration makes it possible to use a name from a namespace.

What is the difference between a template class and class template?
Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates.
Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes.

What is friend function?
§  The function declaration should be preceded by the keyword friend.
§  The function definitions does not use either the keyword or the scope operator ::
§  The functions that are declared with the keyword friend as friend function.
§  Thus, a friend function is an ordinary function or a member of another class.

What is a scope resolution operator?
A scope resolution operator (:, can be used to define the member functions of a class outside the class.

What do you mean by pure virtual functions?
A pure virtual member function is a member function that the base class forces derived classes to provide. Any class containing any pure virtual function cannot be used to create object of its own type.

What is a conversion constructor?
§  A converting constructor is a single-parameter constructor that is declared without the function specifier explicit.
§  The compiler uses converting constructors to convert objects from the type of the first parameter to the type of the converting constructor’s class.

What is a container class? What are the types of container classes
§  A container class is a class that is used to hold objects in memory or external storage.
§  A container class acts as a generic holder.
§  A container class has a predefined behavior and a well known interface.
§  A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory.
§  When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.

What is Associative container?
Associative containers are designed to support direct access to elements using keys. They are not sequential. There are four types of associative containers :
§  Set
§  Multiset
§  Map
§  Multimap

What is an iterator?
Iterators are like pointers. They are used to access the elements of containers thus providing a link between algorithms and containers. Iterators are defined for specific containers and used as arguments to algorithms.

What are the defining traits of an object-oriented language?
The defining traits of an object-oriented language are:
§  Encapsulation
§  Inheritance
§  Polymorphism

What is this pointer?
It is a pointer that points to the current object. This can be used to access the members of the current object with the help of the arrow operator.

Name some pure object oriented languages?
§  Smalltalk
§  Java
§  Eiffel
§  Sather

What is encapsulation?
Encapsulation (or information hiding) is the process of combining data and functions into a single unit called class.

What is problem with Run-time type identification?
The run time type identification comes at a cost of performance penalty. Compiler maintains the class.

What are the differences between new and malloc?
§  New initializes the allocated memory by calling the constructor. Memory allocated with new should be released with delete.
§  Malloc allocates uninitialized memory.
§  The allocated memory has to be released with free.new automatically calls the constructor while malloc(dosen’t)

What is conversion operator?
You can define a member function of a class, called a conversion function, that converts from the type of its class to another specified type.

What do you mean by implicit conversion?
§  Whenever data types are mixed in an expression then c++ performs the conversion automatically.
§  Here smaller type is converted to wider type.
§  Example : in case of integer and float integer is converted into float type.

What are virtual functions?
§  The virtual functions must be members of some class.
§  They cannot be static members.
§  They are accessed by using object pointers.
§  A virtual function can be a friend of another class.

What is the main purpose of overloading operators?
§  The main purpose of operator overloading is to minimize the chances of occurrence of errors in a class that is using the overload operators.
§  It also helps in redefining the functionalities of the operators to improve their performance.
§  Operator overloading also makes the program clearer, readable and more understandable by using common operators, such as +, =, and [].

What is a friend?
Friends can be either functions or other classes. The class grants friends unlimited access privileges.

What is stack unwinding?
Stack unwinding is a process in which a destructor is invoked in a particular program for destroying all the local objects in the stack between throwing and catching of an exception.

What is the form of assignment statement?
Variable = expression ( or constant )

What is the main purpose of overloading operators?
The main purpose of operator overloading is to minimize the chances of occurrence of errors in a class that is using the overloaded operators.

What is this pointer?
When a member function is invoked, the invoking objects pointer is passed implicitly as an argument. This pointer is called this pointer.

What is scope resolution operator?
The Scope resolution operator can be used to define the member functions of a program outside the boundary of a class and not within the class specifier.

What are static members and static functions?
Static members are
§  Created and initialized only once.
§  Shared among all the class objects.
Static functions are
§  Similar to the static variables and are associated with the class.
§  Can only access static variables of a class.
§  Can also be called using the scope resolution operator.

What are the components of a class?
A class consists of two components,
§  Data members
§  Methods

What is the advantage of using templates?

  • Templates provide a means to write generic functions and classes for different data types.
  • Templates are sometimes called parameterized types.
  • Templates can significantly reduce source code size and increase code flexibility without reducing type safety.

Can a function overloading depend only on passing by value and passing by reference?
No, the reason is that whether a function is called the passing a parameter as a value or by reference, it appears similar to the caller of the function.

Is it possible to use a new for the reallocation of pointers?
The reallocation of pointers cannot be done by using new. It can be done by using the realloc() operator.

What are data members?
Data members are variables of any type(in-built or user defined).

What are the types of statements in c++?
A program in any language basically consists of statements. Statements symbolize instructions. There are many categories of statements.
§  Expression statement
§  Assignment statement
§  Selection statement
§  Iteration statement
§  Jump statement

What is initialization?
Initialization is a process of assigning a value to a variable at the time of declaration.

Explain copy constructor?
A copy constructor is a special type of constructor which initializes all the data members of the newly created object by copying the contents of an existing object. The compiler provides a default copy constructor.
Class_name new _ object ( existing object);

What are the advantages of operator overloading?
Operator overloading is used to provide some extra features, behaviors and abilities to the users of a particular class. This feature in C++ helps in controlling the functions performed by an operator and reduces the chance of occurrence of errors in a program.

What is a dangling pointer?
When the location of the deallocated memory is pointed by the pointer even after the deletion or allocation of objects is done, without the modification in the value of the pointer, then this type of pointer is called a dangling pointer.

What is the difference between prefix and postfix versions of operator++()?
§  The prefix and postfix versions of operator ++() can be differentiated on the basis of arguments defined.
§  The postfix operator ++() consists of a dummy parameter of int datatype; whereas, a dummy parameter is not found in the prefix operator ++().

Can a static member function access member variable of an object?
No, because to access the member variable of an object inside its member function, this pointer is required. Since static functions are class functions, this pointer will not be passed as its arguments.

What is the advantages of using the Inline function?
§  An inline keyword before a function suggests the compiler to insert the complete body of the function wherever that function is invoked.
§  Inline expansion is typically used to eliminate the inherent cost involved in calling a function.
§  It is typically used for functions that need quick execution.

What are all the operators that cannot be overloaded?
§  Direct member access operator
§  De–reference pointer to class member operator.*
§  Scope resolution operator::
§  Conditional operator ?:
§  Sizeof operator sizeof

Can a function be overloaded based on return types?
Function signature does not depend on the return type. So overloading cannot be resolved by the return type alone.

What do you mean by a public member?

  • A member declared as public is a public member.
  • It can be accessed freely in a program.

Is recursion allowed in inline functions?
The recursion is allowed in inline function but practically, the inline functions and their properties do not remain inside the program. Moreover, the compiler is not sure about the depth of the recursion at the time of compilation.

What is virtual function?
A virtual function is a member function that is declared within a base class and redefined by a derived class .To create a virtual function, the function declaration in the base class is preceded by the keyword virtual.

How can a struct in C++ differs from a struct in C?

The differences between struct in C++ and C are listed in the following points:

  • In C, the concept of inheritance is not supported. In C++, the concept of inheritance is fully supported.
  • On declaring a struct in C, the addition of the struct keyword is must. On the contrary, there is no need of the struct keyword on declaring struct in C++.
  • In C, the initialization cannot be done outside the scope of a structure. However, in C++, the initialization can be done outside the scope of a structure.
  • In C, structures do not have direct functions or methods.

How the keyword struct is different from the keyword class in C++?
In C++, a class is similar to a struct with the exception that, by default, all the members of a class are private; while the members of a struct are public. Encapsulation is not supported by structures but supported by classes.

Define pure virtual function?
Pure virtual function is defined as a virtual function in a base class. It is implemented in a derived class. A program may not declare an instance of a class that has a pure virtual function.

Define a conversion constructor?
A conversion constructor is a single argument constructor. It is used by the compiler to convert a type of objects as an argument to a class type.

What is a default constructor?
A zero argument constructor or a constructor in which all the arguments have default values is called a default constructor.

What is difference between template and macro?
A template can be used to create a family of classes or function.A template describes a set of related classes or set of related functions in which a list of parameters in the declaration describe how the members of the set vary.
Identifiers that represent statements or expressions are called macros.

What is reference?
Reference is a name that acts as an alias, or alternative name, for a previously defined variable or an object.

What are the access specifier in c++?
There are three types of access specifier in c++ . They are
§  Public
§  protected
§  private

What is difference between C++ and Java?
§  C++ has pointers Java does not.
§  Java is the platform independent as it works on any type of operating systems.
§  java has no pointers where c ++ has pointers.
§  Java has garbage collection C++ does not.

What is namespace?
The C++ language provides a single global namespace. Namespaces allow to group entities like classes, objects and functions under a name.

What is an explicit constructor?
A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It’s purpose is reserved explicitly for construction.Explicit constructors are simply constructors that cannot take part in an implicit conversion.

What is the use of storage class specifiers?
A storage class specifier is used to refine the declaration of a variable, a function, and parameters. The following are storage class specifiers :
§  auto
§  register
§  static
§  extern

what is the assignment operator in c++ and what is its function?
Equal sign ‘=’ is the assignment operator in C++. Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy).

Can destructor be private?
Yes destructors can be private. But it is not advisable to have destructors as private.

What is strstream?
string-stream provides an interface to manipulate strings as if they were input/output streams.
‹strstream› to define several classes that support iostreams operations on sequences stored in an allocated array of char object.

What is the difference between method overloading and method overriding?
Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters).
Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

What is STL? And what are the components of STL?
A collection of generic classes and functions is called as Standard Template Library (STL). STL components are

  • Containers
  • Algorithm

IteratorsD

2 Comments

  1. Ayesha Mumtaz

    Question No: 1 ( Marks: 2 )
    Write a declaration statement for an array of 10 elements of type float. Include an initialization statement of the first four elements to 1.0, 2.0, 3.0 and 4.0.
    Answer:

    float floatArry[10] = {1.0,2.0,3.0,4.0};

    Question No: 2 ( Marks: 2 )
    Write the general syntax for the declaration of pre-increment and postincrement member operator function.
    Answer:

    Classname operator ++(); —- pre increment
    Classname operator ++(int) —- post increment

    Question No: 3 ( Marks: 2 )
    Give the general syntax of class template.
    Answer:

    template
    class myclass { —} ;

    Question No: 4 ( Marks: 2 )
    What is a truth Table?
    Answer:

    There are some areas where the decision structures become very complicated. Sometimes, we find it difficult to evaluate a complicated logical expression. Sometimes the logic becomes extremely
    Page. No. 2/15
    complicated so that even writing it as a simple syntax statement in any language. It becomes complicated to determine what will be evaluated in what way. We know the concept of truth table. The truth tables are very important. These are still a tool available for analyzing logical expressions. We will read logic design in future, which is actually to do with chips and gates. How we put these things together.

    Question No: 5 ( Marks: 2 )
    What will be the output of following code, if user input a
    number 123?

    int input ;
    cin >> oct >> input;
    cout << hex << input ;
    Answer:
    53
    Rational: it will take 123 as octal and print it in hex form which is 53.

    Question No: 6 ( Marks: 2 )
    What is principle of friendship in the context of functions and classes?
    Answer:

    Class can declare a friend function and someone from outside the class cannot declare itself friend of a class.
    A friend function can access the private variables of class just like a member function

    Question No: 7 ( Marks: 2 )
    How many arguments a Unary Operator take? Can we make a binary operator as unary operator?
    Answer:

    Unary operator takes only one argument like i++ or i— (Post increment or post decrement operators for integers) or ++i,–i (Pre increment or pre decrement operators for integers) ,we can not make
    Unary operator as binary or binary as Unary operator.

    Question No: 8 ( Marks: 2 )
    Which arithmetic operators cannot have a floating point operand?
    Answer:

    Modulus operator:
    This operator can only be used with integer operands ONLY

    Question No: 9 ( Marks: 2 )
    What are manipulators? Give one example.
    Answer:

    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.

    Question No: 18 ( Marks: 2 )
    What is difference between endl and \n?
    Answer:

    Endl is manipulator and it inserts new line character and flushes the stream.
    Page. No. 6/15
    \n is control character which is used to insert line break.

    Question No: 19 ( Marks: 2 )
    What does code optimization mean?
    Answer:

    It is process by which we make our code such a way that it improves the speed of program. By use of optimization we refine program codes in such a way that it run faster and consume less memory. We do it in such a way that output quality is not compromised.

    Question No: 20 ( Marks: 3 )
    How is the following cout statement interpreted by compiler?
    cout << a << b << c ;
    Answer:

    It will give a compiler error because a,b,c are not declared.

    Question No: 21 ( 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?
    Answer: A
    (ii) The destructor of which class will be called first?
    Answer: B

    Question No: 23 ( Marks: 3 )
    If is not available in the system then what does calloc/malloc and new operator return?
    Answer:

    calloc/malloc and new operator return returns a null pointer to indicate that no memory is available

    Question No: 24 ( Marks: 3 )
    What is the keyword ‘this’ and what are the uses of ‘this’ pointer?
    Answer:

    'this' is use to refer the current class member without using the name of the class.

    Question No: 26 ( Marks: 3 )
    What will be the output of following function if we call this function by passing int 5?
    template T reciprocal(T x) {return (1/x); }
    Answer:

    0
    The output will zero as 1/5 and its .05 but conversion to int make it
    zero
    Above is prototype of template class so assume passing an int and
    returning an int

    Question No: 28 ( Marks: 3 )
    What are the limitations of the friendship relation between classes?
    Answer:

    friendship relation between classes is a one way relation that is if one class declare friend another class then the another class is the friend of first class but not the first class if the friend of another class.

    Question No: 31 ( Marks: 5 )
    What steps we must follow to design good program?
    Answer 1:

    Hence to design a program properly, we must:
     Analyze a problem statement, typically expressed as a word problem.
     Express its essence, abstractly and with examples.
     Formulate statements and comments in a precise language.
     Evaluate and revise the activities in light of checks and tests and
     Pay attention to detail.

    Answer 2:
    Details: we must check very details of any program. It is very important aspect of any program. We must pay complete attention to calculation.
    We must give attention to logic and its flow should be smooth.
    Reusable: We must write program in such a way that we can reuse them in other program. Like we define function in such a way that in future if we need any similar kind of function is requires in that case we can easily modify or reuse it.
    Comments: we write the details of important steps in the form of comments. We should use comments in such a way if any body else wanted to reuse or debug or codes he can easily understand it. Code readability: We should use Tab and spaces so codes are easily readable. User interface: we make interface user friendly. Use polite prompts for user while take input.

    Question No: 36 ( Marks: 5 )
    What are the advantages and disadvantages of using templates?
    Page. No. 13/15
    Answer:

    Many things can be possible without using templates but it does offer several clear advantages not offered by any other techniques:
    Advantages:
     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 helps 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.

Submit a Comment