0% found this document useful (0 votes)
10 views

C++

Uploaded by

josephwanjiku835
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

C++

Uploaded by

josephwanjiku835
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ QUIZ

1. Discus any five features of C++ programming language


❖ Object oriented programming>C++ supports OOP which allows for the creation of
objects that represent real world entities
❖ Control structures>C++ provides various control structures like loops, conditional
and branching statements to control the flow of program
❖ Pointers>C++ allows the use of pointers to manipulate memory directly, providing
low level access to memory
❖ Dynamic memory allocation>C++ supports memory allocation, allowing for the
allocation and deallocation of memory during runtime
❖ Templates>C++ supports template, which allow for the creation of generic functions
and classes that can work with different data types
2. Give the difference between equals to (==) and assignment operator (=)
❖ Equal to operator (==): It is used to compare two values to see if they are equal
❖ Assignment operator (=): It is used to assign a value to a variable
3. List the five tokens found in C++
❖ Keywords: Reserved words in C++ such as int, float, class, etc.
❖ Operators: Symbols that perform operations such as +, -, *, /, etc.
❖ Identifiers: names given to variables, functions, and other entities in a program
❖ Constants: fixed values that do not change during execution, such as10, 3, 4, etc.
❖ Separators: symbols that separate different parts of a program, such as commas,
semicolon, etc.
4. Explain any five differences between C and C++
❖ OOP: C++ supports OOP while C does not
❖ Control structures: C++ has additional control structures such as namespaces and
exceptions that are not available in C
❖ Memory management: C++ provides more advanced memory management features
such as smart pointers and dynamic memory allocation
❖ Standard libraries: C++ has a larger standard library compared to C, providing more
built-in functions and data structures
❖ Compatibility: C++ is designed to be backward compatibility with C, meaning that
C++ can run programs written in C
5. Write C++ algorithm code to remove spaces in the string
#include<iostream>
#include<string>
Using namespace std;

Int main(){
String str;
cout<<”Enter a string:”;
getline(cin,str);
string result= str;
for (int i=0;i<str.length();i++){
if (str[i]==’){
str.erase(I,1);
i--;
}
}
}
Cout<<”Result:”<<str<<endI;
Return 0:
}

6. State the rules for naming the identifiers in C++ programming language
❖ Only alphabetic chars, digits and underscores are permitted
❖ The name can’t start with a digit
❖ Upper case and lower case letters are distinct
❖ A declared keyword can’t be used as a variable name
7. List any two applications of OOP
❖ Graphical user interfaces (GUIs): OOP is used to create graphical user interface,
where objects represent different components of the interface such as buttons,
menus and windows
❖ Game development: OOP is used to create games, where objects represent different
game elements such as characters, enemies and obstacles
8. Explain what are access modifiers and list the three types of access modifiers
✓ Access modifiers are used to control accessibility of class members
Types of access modifiers in C++
• Public: members declared as public can be accessed from anywhere, including
outside the class
• Private: members declared private can only be accessed from within the class
• Protected: members declared protected can be accessed from within the class and
its derived classes
9. What do you understand about polymorphism in C++?
• Polymorphism is a feature of OOP that allows object of different classes to be
treated as if they were objects of the same class. Polymorphism enables the use of a
single function or operator to handle different types of data, making the code more
flexible and reusable
10. Discuss how structure is different from class
❖ Structure: It is a value type data type that can contain a combination of data types
such as integers, floats and characters.it is typically used to represent a collection of
related data items
❖ Class: It is a user defined data type that can contain data members and member
functions

You might also like