CBSE Class 12 Computer Science: Chapter 1 - C++ Revision Tour Solutions
This section provides NCERT Solutions for Class 12 Computer Science, focusing on Chapter 1: C++ Revision Tour - Basics of C++. It covers fundamental C++ concepts, including essential library functions for character input/output and manipulation. The solutions explain how to identify necessary header files like <stdio.h>, <ctype.h>, and <string.h> for successful program compilation and execution. Students will learn to recognize functions such as getchar(), isalnum(), isupper(), toupper(), tolower(), gets(), strcpy(), and strrev(). These solutions are designed to reinforce basic programming skills and prepare students for understanding more complex C++ topics, aiding in effective exam revision.
Quick info
| Board | CBSE |
|---|---|
| Class | Class 12 |
| Subject | Computer Science (C++) |
| Session | 2026 |
| Language | English |
| Type | NCERT Solutions |
| Chapter | Chapter 1 |
Chapter summary
Chapter 1 of the CBSE Class 12 Computer Science syllabus, "C++ Revision Tour - Basics of C++," revisits fundamental programming concepts. This NCERT Solutions set focuses on identifying and utilizing standard C++ library functions and their corresponding header files. It covers input/output operations, character handling, and string manipulation, ensuring students have a solid grasp of these essential building blocks before proceeding to advanced topics. The exercises are designed to test understanding of basic syntax and library function requirements.
Learning outcomes
- Identify and name essential C++ library functions for character and string manipulation.
- Determine the necessary header files required for compiling C++ programs.
- Understand the purpose of functions like getchar(), isalnum(), isupper(), toupper(), tolower(), gets(), strcpy(), and strrev().
- Apply knowledge of header files to ensure successful program compilation.
- Differentiate between character and string handling functions in C++.
Topics covered
Paper topics
- Basics of C++
- Library Functions
- Header Files
- Character Input/Output
- Character Manipulation
- String Manipulation
- getchar() function
- isalnum() function
- isupper() function
- toupper() function
- tolower() function
- stdio.h
- ctype.h
- string.h
Important topics
- Identifying necessary header files for C++ programs
- Understanding and using character handling functions (isalnum, isupper, toupper, tolower)
- Basic input/output functions (getchar, puts)
- String manipulation functions (gets, strcpy, strrev)
PDF preview
Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.
Questions and Solutions
Question 1
- Get single character using keyboard. This function is available in stdio.h file.
- To check whether given character is alpha numeric character or not. This function is available in ctype.h file.
The library functions corresponding to the given descriptions are:
- For getting a single character from the keyboard, the function is
getchar(). This function is declared in the<stdio.h>header file. - To check if a given character is alphanumeric (either a letter or a digit), the function is
isalnum(). This function is declared in the<ctype.h>header file.
Question 2
typedef char TEXT[80];
void main() { TEXT Str[] = "Peace is supreme";
int Index = 0;
while(Str[Index] != '\0')
if(isupper(Str[Index]))
Str[Index++] = '#';
else
Str[Index++] = '*';
puts(Str); }
To compile and execute the given C++ program successfully, the following header files are essentially required:
<ctype.h>: This header file is necessary because the program uses theisupper()function, which checks if a character is an uppercase letter.<stdio.h>: This header file is required for theputs()function, which is used to print the modified string `Str` to the console. It also contains declarations for standard input/output operations.
The `typedef` statement and the `main` function structure are standard C++ constructs, but the specific functions used (`isupper`, `puts`) necessitate these particular header files.
Question 3
void main() { char str[20], str1[20];
gets(str);
strcpy(str1, str);
strrev(str);
puts(str);
puts(str1); }
The following header files are needed for the successful compilation of the provided C++ code:
#include<stdio.h>: This header file is required for input/output functions such asgets()(to read a string) andputs()(to print a string).#include<string.h>: This header file is necessary because the code uses string manipulation functions likestrcpy()(to copy a string) andstrrev()(to reverse a string).
Note: The use of `gets()` is generally discouraged in modern C++ programming due to security risks (buffer overflow). Functions like `fgets()` are preferred.
Question 4
void main() { char CH, STR[20];
cin >> STR;
CH = toupper(STR[0]);
cout << STR << " starts with " << CH << endl; }
The following header files are essentially required to compile and run the given C++ code:
#include<iostream.h>: This header file provides the definitions for standard input/output stream objects likecin(for input) andcout(for output), as well as manipulators likeendl.#include<ctype.h>: This header file is needed because the code uses thetoupper()function, which converts a lowercase character to its uppercase equivalent.
The code reads a string, converts its first character to uppercase, and then prints the original string along with the uppercase first character.
Question 5
void main() { char Text[20], C;
cin >> Text;
C = tolower(Text[0]);
cout << C << " is the first char of " << Text << endl; }
The following header files are essential for the successful compilation and execution of the provided C++ code:
#include<iostream.h>: This header file is required for using the standard input stream objectcinto read the string `Text` and the standard output stream objectcoutalong with the manipulatorendlto display the result.#include<ctype.h>: This header file is necessary because the code utilizes thetolower()function, which converts an uppercase character to its lowercase equivalent.
The program takes a string as input, converts its first character to lowercase, and then prints this lowercase character followed by a descriptive message.
Common mistakes
- Forgetting to include necessary header files, leading to compilation errors.
- Confusing the purpose or syntax of similar character manipulation functions (e.g., isupper vs. toupper).
- Incorrectly identifying the return type or usage of standard library functions.
- Not recognizing the need for specific header files for string manipulation functions.
Revision tips
- Review the purpose of each listed header file and the functions it contains.
- Practice identifying the correct header file for given code snippets.
- Trace the execution of simple programs involving character and string functions.
- Create small programs to test the behavior of functions like isalnum(), toupper(), and strrev().
Practice MCQs
Q1. Which header file is required for the `getchar()` function in C++?
Explanation: The `getchar()` function, used for reading a single character from the keyboard, is declared in the `<stdio.h>` (Standard Input/Output) header file.
Q2. The `isalnum()` function checks if a character is:
Explanation: `isalnum()` is a function from `<ctype.h>` that returns true if the given character is either an alphabet (a-z, A-Z) or a numeric digit (0-9).
Q3. Which header file contains the `strcpy()` function for string copying?
Explanation: The `strcpy()` function, used to copy one string to another, is part of the string manipulation library and is declared in the `<string.h>` header file.
Q4. To use `toupper()` and `tolower()` functions, which header file must be included?
Explanation: Functions like `toupper()` (convert to uppercase) and `tolower()` (convert to lowercase) are character handling functions and are found in the `<ctype.h>` header file.
Q5. What is the primary purpose of the `puts()` function?
Explanation: `puts()` is a standard C library function used to display a string followed by a newline character on the standard output.
Frequently asked questions
What are the essential header files for basic C++ programming?
For basic C++ programming involving input/output and character/string manipulation, essential header files include `<iostream.h>` (for `cin`, `cout`), `<stdio.h>` (for `getchar`, `puts`, `gets`), `<ctype.h>` (for character checking/conversion like `isalnum`, `isupper`, `toupper`), and `<string.h>` (for string functions like `strcpy`, `strrev`).
How do I know which header file to include for a specific function?
You need to know the standard C++ libraries. For example, input/output functions are typically in `<stdio.h>` or `<iostream.h>`, character functions in `<ctype.h>`, and string functions in `<string.h>`. Consulting documentation or examples helps identify the correct header.
What is the difference between `gets()` and `cin >>` for reading strings?
`cin >>` reads input until whitespace is encountered, while `gets()` reads the entire line of input, including spaces, until a newline character is found. However, `gets()` is generally considered unsafe due to potential buffer overflows and is often deprecated.
What does the `isalnum()` function do?
The `isalnum()` function, found in `<ctype.h>`, checks if a given character is alphanumeric, meaning it is either a letter (a-z, A-Z) or a digit (0-9). It returns a non-zero value (true) if it is, and 0 (false) otherwise.
Why is it important to include the correct header files?
Including the correct header files is crucial because they contain the declarations for the functions, classes, and variables that your program uses. Without these declarations, the compiler cannot understand how to use these elements, leading to compilation errors.
Content reviewed by the NCERT Help team. Editorial Team and update policy
NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.