CBSE Class 12 Computer Science: C++ Revision Tour NCERT Solutions

NCERT Solutions PDF Class 12 PDF

CBSE Class 12 Computer Science NCERT Solutions for Chapter 1, C++ Revision Tour, offer a comprehensive review of foundational C++ concepts. This chapter delves into essential library functions vital for character input, output, and manipulation. Students will learn to identify and utilize appropriate header files, such as <stdio.h>, <ctype.h>, and <iostream.h>, which are critical for program compilation and execution. The solutions meticulously explain the practical application of key functions including getchar(), isalnum(), isupper(), strrev(), toupper(), and tolower(), detailing their specific roles and the header files they are associated with. This resource aims to solidify students' grasp of basic C++ syntax and standard library components, providing a robust foundation for their upcoming examinations and future programming endeavors.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science
Session2026
LanguageEnglish
TypeNCERT Solutions
Chapter1. C++ Revision Tour

Chapter summary

Chapter 1, C++ Revision Tour, focuses on reinforcing foundational C++ concepts. This NCERT Solutions set covers the identification of essential header files required for various C++ programs, including those dealing with character input/output and string manipulation. It also touches upon basic character checking and conversion functions, ensuring students can recall and apply these fundamental building blocks of C++ programming.

Learning outcomes

  • Identify essential C++ header files for given code snippets.
  • Recall the purpose of standard C++ library functions.
  • Understand the role of functions like getchar(), isalnum(), isupper(), strrev(), toupper(), and tolower().
  • Determine the necessary header files for character and string manipulation in C++.

Topics covered

Paper topics

  • C++ Basics
  • Header Files
  • Library Functions
  • Character Input/Output
  • Character Checking
  • String Manipulation
  • stdio.h
  • ctype.h
  • string.h
  • iostream.h
  • getchar()
  • isalnum()

Important topics

  • Identifying essential header files
  • Understanding character handling functions (isalnum, isupper, toupper, tolower)
  • Basic string manipulation functions (strrev)
  • Input/Output stream functions (cin, cout)

PDF preview

Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.

Loading document …
Page of
Loading page …

Questions and Solutions

Question 1

Write the related library function name based upon the given information in C++.
  1. Get single character using keyboard. This function is available in stdio.h file.
  2. To check whether given character is alpha numeric character or not. This function is available in ctype.h file.
Solution:

To fulfill the requirements described, the following standard C++ library functions are used:

  1. The function to get a single character from the keyboard, which is available in the `stdio.h` header file, is getchar().
  2. The function to check if a given character is alphanumeric (either a letter or a digit), available in the `ctype.h` header file, is isalnum().

Question 2

Observe the following program very carefully and write the names of those header file(s), which essentially needed to compile and execute the following program successfully:

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);
}

Solution:

For the successful compilation and execution of the provided C++ program, the following header files are essentially required:

  • `ctype.h : This header file is necessary because the program uses the isupper() function, which is part of the character handling library.
  • `stdio.h : This header file is required for the puts() function, which is used to print the modified string to the console.

Question 3

Name the header files that shall be needed for successful compilation of the following C++ code:

void main() {
  char str[20], str1[20];
  gets(str);
  strcpy(str1, str);
  strrev(str);
  puts(str);
  puts(str1);
}

Solution:

The following header files are necessary for the successful compilation of the given C++ code:

  • `#include <stdio.h> : This is required for input/output functions like gets() and puts().
  • `#include <string.h> : This header file is needed for string manipulation functions such as strcpy() and strrev().

Note: The use of gets() is generally discouraged due to security risks; fgets() is a safer alternative.

Question 4

Observe the following C++ code and write the name(s) of the header file(s), which will be essentially required to run it in a C++ compiler:

void main() {
  char CH, STR[20];
  cin >> STR;
  CH = toupper(STR[0]);
  cout << STR << " starts with " << CH << endl;
}

Solution:

To ensure the provided C++ code compiles and runs correctly, the following header files must be included:

  • `#include <iostream.h> : This header file is essential for using the standard input stream object cin, the standard output stream object cout, and the stream manipulator endl.
  • `#include <ctype.h> : This header file is required because the code utilizes the toupper() function, which converts a character to its uppercase equivalent.

Question 5

Observe the following C++ code and write the name(s) of the header file(s), which will be essentially required to run it in a C++ compiler:

void main() {
  char Text[20], C;
  cin >> Text;
  C = tolower(Text[0]);
  cout << C << " is the first char of " << Text << endl;
}

Solution:

The following header files are necessary for the proper compilation and execution of the given C++ code:

  • `#include <iostream.h> : This header provides the definitions for input/output stream objects like cin and cout, as well as the endl manipulator used in the code.
  • `#include <ctype.h> : This header file contains the declaration for the tolower() function, which converts a character to its lowercase equivalent.

Common mistakes

  • Forgetting to include necessary header files.
  • Confusing the purpose of similar-named library functions.
  • Incorrectly identifying the header file for a specific function.

Revision tips

  • Review the purpose of each standard C++ header file covered.
  • Practice identifying header files based on the functions used in code.
  • Create small programs to test the functionality of functions like isalnum() and strrev().
  • Pay close attention to the exact function names and their corresponding header files.

Practice MCQs

Q1. Which header file is required for the `getchar()` function in C++?

Q2. The `isalnum()` function checks if a character is alphanumeric. Which header file contains this function?

Q3. Which header file is essential for using the `strrev()` function in C++?

Q4. To use `cin`, `cout`, and `endl` in a C++ program, which header file must be included?

Q5. The `toupper()` function converts a lowercase letter to uppercase. Which header file is needed for `toupper()`?

Frequently asked questions

What is the purpose of the C++ Revision Tour chapter?

The C++ Revision Tour chapter aims to refresh students' understanding of fundamental C++ concepts, including essential header files and basic library functions, before moving to more advanced topics.

Which header file is commonly required for input and output operations in C++?

The `<iostream.h>` header file is essential for standard input and output operations using objects like `cin` and `cout`.

What is the difference between `<stdio.h>` and `<iostream.h>`?

`<stdio.h>` is inherited from C and provides functions like `printf` and `scanf`, while `<iostream.h>` is the C++ standard for stream-based input/output using objects like `cout` and `cin`.

How do functions like `isalnum()` and `isupper()` help in C++ programming?

These functions, found in `<ctype.h>`, help in classifying characters. `isalnum()` checks if a character is alphanumeric, and `isupper()` checks if it is an uppercase letter, aiding in data validation and processing.

Why is it important to know the correct header files for C++ functions?

Including the correct header file ensures that the compiler can locate and link the necessary function definitions, allowing the program to compile and execute successfully. Missing header files lead 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.