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

Chapter-10 Standard Library Functions Type A: Very Short Answer Questions

This document contains sample questions and answers about standard library functions in C++. It includes: 1) Short definitions of common standard library header files like iomanip.h, string.h, ctype.h, and math.h and functions they contain. 2) Examples of C++ programs that use standard library functions to manipulate strings, convert cases, and compare lengths. 3) Short questions and answers testing understanding of which header files functions like strcpy(), toupper(), and cos() belong to.

Uploaded by

Rachna Anand
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Chapter-10 Standard Library Functions Type A: Very Short Answer Questions

This document contains sample questions and answers about standard library functions in C++. It includes: 1) Short definitions of common standard library header files like iomanip.h, string.h, ctype.h, and math.h and functions they contain. 2) Examples of C++ programs that use standard library functions to manipulate strings, convert cases, and compare lengths. 3) Short questions and answers testing understanding of which header files functions like strcpy(), toupper(), and cos() belong to.

Uploaded by

Rachna Anand
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CHAPTER-10

STANDARD LIBRARY FUNCTIONS


TYPE A : VERY SHORT ANSWER QUESTIONS
1. What is standard library?
Ans. A standard library is a collection of subprograms used to develop other program and software.
2. Why is C++ standard library needed?
Ans. So that users can use their desiered functions (available through standard library) at their wish.
3. What are the functions of these header files?
iomanip.h, string.h, ctype.h, math.h
Ans. iomanip.h – This file declares the C++ streams I/O manipulators and contains macros for creating parameterized
manipulators.
string.h – This header file declares several string manipulations and memory manipulation routines.
ctype.h – This header file declares several character manipulations functions and the argument type of these
functions is int.
math.h - This header file declares prototypes for the math functions and math error handlers.
4. Which of the following functions appends a string to another string?
strcpy(), strcmp(), strcat(), toupper()
Ans. strcat()
5. Distinguish between the following functions:
(i) islower() and tolower() (ii) isupper() and toupper()
Ans. (i) islower() and tolower(): The islower() function checks whether the given character is in lower case or not,
whereas tolower() functions converts the given character in to lower case.
(ii) isupper() and toupper(): The isupper() function checks whether the given character is in upper case or not,
whereas toupper() functions converts the given character in to upper case.
6. Name the header file, to which following built-in functions belong to:
(i) cos (ii) setw() (ii) toupper() (iv) strcpy()
Ans. (i) cos – math.h (ii) setw() – iomanip.h (ii) toupper() – ctype.h (iv) strcpy() – string.h
7. Name the header file, to which following built-in functions belong:
(i) isalnum (ii) gets() (iii) fabs (iv) strlen
Ans. (i) isalnum – ctype.h (ii) gets() – stdio.h (iii) fabs – math.h (iv) strlen – string.h
TYPE B : SHORT ANSWER QUESTIONS
1. Write a C++ program that converts lower case letters in a given string to corresponding upper case letters, and
vice versa.
Ans. #include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[50];
int i=0;
cout<<"Enter string: ";
gets(str);
while(i<strlen(str))
{
if(str[i]>=65 && str[i]<=90)
{
str[i]=tolower(str[i]);
}
else if(str[i]>=97 && str[i]<=122)
{
1

http://cbsecsnip.in
str[i]=toupper(str[i]);
}
i++;
}
puts(str);
getch();
}
2. Write a C++ program that reads three strings and prints the longest and smallest string.
Ans. #include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[50],str2[50],str3[50];
int i=0,a,b,c;
cout<<"Enter string1: ";
gets(str1);
cout<<"Enter string2: ";
gets(str2);
cout<<"Enter string3: ";
gets(str3);
a=strlen(str1);
b=strlen(str2);
c=strlen(str3);
if((a>b) && (a>c))
cout<<"Largest string: "<<str1;
else if((b>a) && (b>c))
cout<<"Largest string: "<<str2;
else
cout<<"Largest string: "<<str3;
if((a<b) && (a<c))
cout<<endl<<"Smallest string: "<<str1;
else if((b<a) && (b<c))
cout<<endl<<"Smallest string: "<<str2;
else
cout<<endl<<"Smallest string: "<<str3;
getch();
}
3. Write a program that reads a string and a character. Each occurrence of the given character (regardless of its case)
is converted to opposite case. For example, if the string entered is:
AabrAcadabrA and the character as A or a then the output string should be aAbracAdAbra. See each a or A is
converted to opposite case i.e., upper to lower or vice-versa.
Ans. #include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
char str[50],ch;
int i=0,l;
int result=0,result1=0;
cout<<"Enter strings: ";
gets(str);

http://cbsecsnip.in
cout<<"Enter charcter: ";
cin>>ch;
while(str[i]!='\0')
{
if(toupper(ch)== str[i])
{
str[i]=tolower(str[i]);
}
else if(tolower(ch)== str[i])
{
str[i]=toupper(str[i]);
}
i++;
}
puts(str);
getch();
}

http://cbsecsnip.in

You might also like