CBSE Class 12 Computer Science: Chapter 1 - C++ Revision Tour Solutions

NCERT Solutions PDF Class 12 PDF

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

BoardCBSE
ClassClass 12
SubjectComputer Science (C++)
Session2026
LanguageEnglish
TypeNCERT Solutions
ChapterChapter 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.

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:

The library functions corresponding to the given descriptions are:

  1. For getting a single character from the keyboard, the function is getchar(). This function is declared in the <stdio.h> header file.
  2. 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

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:

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 the isupper() function, which checks if a character is an uppercase letter.
  • <stdio.h>: This header file is required for the puts() 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

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 needed for the successful compilation of the provided C++ code:

  • #include<stdio.h>: This header file is required for input/output functions such as gets() (to read a string) and puts() (to print a string).
  • #include<string.h>: This header file is necessary because the code uses string manipulation functions like strcpy() (to copy a string) and strrev() (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

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:

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 like cin (for input) and cout (for output), as well as manipulators like endl.
  • #include<ctype.h>: This header file is needed because the code uses the toupper() 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

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 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 object cin to read the string `Text` and the standard output stream object cout along with the manipulator endl to display the result.
  • #include<ctype.h>: This header file is necessary because the code utilizes the tolower() 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++?

Q2. The `isalnum()` function checks if a character is:

Q3. Which header file contains the `strcpy()` function for string copying?

Q4. To use `toupper()` and `tolower()` functions, which header file must be included?

Q5. What is the primary purpose of the `puts()` function?

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.