Please refer to CBSE Class 12 Computer Science HOTs Programming in C++ Two mark Questions. Download HOTS questions and answers for Class 12 Computer Science. Read CBSE Class 12 Computer Science HOTs for Programming in C++ below and download in pdf. High Order Thinking Skills questions come in exams for Computer Science in Class 12 and if prepared properly can help you to score more marks. You can refer to more chapter wise Class 12 Computer Science HOTS Questions with solutions and also get latest topic wise important study material as per NCERT book for Class 12 Computer Science and all other subjects for free on Studiestoday designed as per latest CBSE, NCERT and KVS syllabus and pattern for Class 12
Programming in C++ Class 12 Computer Science HOTS
Class 12 Computer Science students should refer to the following high order thinking skills questions with answers for Programming in C++ in Class 12. These HOTS questions with answers for Class 12 Computer Science will come in exams and help you to score good marks
HOTS Questions Programming in C++ Class 12 Computer Science with Answers
<p></p>
2 Marks Questions
Programming in C++
Q.1. Rewrite the following codes after removing errors, if any, in the following snippet.
Explain each error.
#include<iostream.h>
void main( )
{
int x[5], *y, z[5]
for (i = 0; i < 5; i ++
{
x[i] = i;
z[i] = i + 3;
y = z;
x = y;
}
Ans.1. In this question first we have to write complete program after removing all the errors.
#include<iostream.h>
void main( )
{
int x[5], *y, z[5] ; // semi colon must be used here
for ( int i = 0; i < 5; i ++) // data type of i and closing ) should be there.
{
x[i] = i;
z[i] = i + 3;
*y = z; // wrong assignment ( integer to pointer)
x = *y; // wrong assignment ( Pointer to integer)
}
Q.2. Rewrite the following program after removing the error(s), if any. Underline each
correction.
#include <iostream.h>
void main( )
{
int x, sum =0;
cin>>n;
for (x=1;x<100, x+=2)
if x%2=0
sum+=x;
cout<< “sum=” >>sum;
}
Ans 2. Corrected code:
#include <iostream.h>
void main()
{
int x, sum =0;
cin >> x ; // x in place of n
for (x=1; x<100 ; x+=2) //semicolon
if x%2= = 0 // double =due to assignment
sum+=x;
cout<< “sum=” << sum; //<<
}
Q.3. Rewrite the following program after removing the syntactical error(s), if any Underline
each correction:
#include <iostream.h>
void main( )
{
struct Book
{
char Book_name[20];
char Publisher_name[20];
int Price = 170;
} New Book;
gets(Book_name);
gets(Publisher_name);
}
Ans.3. #include <iostream.h>
#include<stdio.h>
void main( )
{
struct Book
{
char Book_name[20];
char Publisher_name[20];
int Price;
} Book New;
gets(New. Book_name);
gets(New. Publisher_name);
}
Q.4. Rewrite the following program after removing the syntactical errors (if any).
Underline each correction.
#include [iostream.h]
class MEMBER
{
int Mno;float Fees;
PUBLIC:
void Register(){cin>>Mno>>Fees;}
void Display{cout<<Mno<<" : "<<Fees<<endl;}
};
void main()
{
MEMBER M;
Register();
M.Display();
}
Ans.4. #include <iostream.h>
class MEMBER
{
int Mno;float Fees;
public:
void Register(){cin>>Mno>>Fees;}
void Display(){cout<<Mno<<":"<<Fees<<endl;}
};
void main()
{
MEMBER M;
M.Register();
M.Display();
}
Q.5. Rewrite the following program after removing the syntactical errors (if any). Underline
each correction.
#include <iostream.h>
struct Pixels
{ int Color,Style;}
void ShowPoint(Pixels P)
{ cout<<P.Color,P.Style<<endl;}
void main()
{
Pixels Point1=(5,3);
ShowPoint(Point1);
Pixels Point2=Point1;
Color.Point1+=2;
ShowPoint(Point2);
}
Ans 5. #include <iostream.h>
struct Pixels
{ int Color,Style;} ;
void ShowPoint(Pixels P)
{ cout<<P.Color<<P.Style<<endl;}
void main()
{
Pixels Point1={5,3};
ShowPoint(Point1);
Pixels Point2=Point1;
Point1.Color+=2;
ShowPoint(Point2);
}
Q.6. Rewrite the following program after removing the error(s), if any. Underline each
correction.
#include <iostream.h>
void main( )
{
int x, sum =0;
cin>>n;
for (x=1;x<100, x+=2)
if x%2=0
sum+=x;
cout<< “sum=” >>sum;
}
Ans.6. #include <iostream.h>
void main( )
{
int x, sum =0;
cin >> x ; // x in place of n
for (x=1; x<100 ; x+=2) //semicolon
if x%2= = 0 // double =
sum+=x;
cout<< “sum=” << sum; //<<
Q.7. Will the following program execute successfully? If no, state the reason(s) :
#include<iostream.h>
#include<stdio.h>
#define int M=3;
void main( )
{
const int s1=10;
int s2=100;
char ch;
getchar(ch);
s1=s2*M;
s1+M = s2;
cout<<s1<<s2 ;
}
Ans.7. #include<iostream.h>
#include<stdio.h>
#define int M=3;
void main( )
{
const int s1=10;
int s2=100;
char ch;
getchar(ch);
s1=s2*M;
s1+M = s2;
cout<<s1<<s2 ;
}
Q. 8. Rewrite the following program after removing the syntactical errors (if any). Underline
each correction.
#include<iostream.h>
void main()
{
char arr{} = {12, 23, 34, 45};
int ptr = arr;
int val = *ptr; cout << *val << endl;
val = *ptr++; cout << val << endl;
val = *ptr : cout << val >> endl;
val = *++ptr; cout << val << endl;
}
Ans.8. include<iostream.h>
void main()
{
int arr[ ] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *ptr++; cout << val << endl;
val = *ptr ; cout << val >> endl;
val = *++ptr; cout << val << endl;
}
Q.9. Rewrite the following program after removing the syntactical error (s), if any. Underline
each correction.
#include<iostream.h>
const int dividor 5;
void main( )
{ Number = 15;
for(int Count=1;Count=<5;Count++,Number -= 3)
if(Number % dividor = 0)
{
cout<<Number / Dividor;
cout<<endl;
}
else
cout<<Number + Dividor <<endl;
}
Ans.9. #include<iostream.h>
const int dividor= 5;
void main( )
{
int Number = 15;
for(int Count=1;Count<=5;Count++,Number -= 3)
if(Number % dividor = = 0)
{
cout<<Number / Dividor;
cout<<endl;
}
else
cout<<Number + Dividor <<endl; }
Q.10 Rewrite the following program after removing the syntactical error(s) if any. Underline
each correction.
#include<iostream.h>
void main( )
{
First = 10, Second = 30;
Jumpto(First;Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2 = 20)
{
N1=N1+N2;
count<<N1>>N2;
}
Ans.10. #include<iostream.h>
void Jumpto(int N1,int N2=20); //Prototype missing
void main( )
{
int First = 10, Second = 30; //Data type missing
Jumpto(First , Second); //Comma to come instead of ;
Jumpto(Second);
}
void Jumpto(int N1, int N2=20)
{
N1=N1+N2;
cout<<N1<<N2; //Output operator << required
}
Q.11. Rewrite the following program after removing the syntactical error(s) if any. Underline
each correction.
#include<iostream.h>
const int Max 10;
void main()
{
int Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc];
}
Ans.11. #include<iostream.h>
const int Max = 10; //Constant Variable ‘Max’ must be
//initialized. Declaration Syntax Error
void main( )
{
int Numbers[Max]={20,50,10,30,40};
for(Loc=Max-1;Loc>=0;Loc--)
cout>>Numbers[Loc];
}
Q.12. Rewrite the following program after removing the syntactical error(s), if any. Underline
each correction.
#include<iostream.h>
const int Multiple 3;
void main( )
{
value = 15;
for(int Counter = 1;Counter = <5;Counter ++, Value -= 2)
if(Value%Multiple = = 0)
{
cout<<Value * Multiple;
cout<<end1;
}
else
cout<<Value + Multiple <<endl; }
Ans.12. #include<iostream.h>
const int Multiple=3;
void main( )
{
int Value = 15;
for(int Counter = 1;Counter <=5;Counter ++, Value -= 2)
if(Value%Multiple == 0)
{
cout<<Value * Multiple;
cout<<endl;
}
else
cout<<Value + Multiple <<endl;}
Q.13. Will the following program execute successfully? If not, state the reason(s). 2
#include<stdio.h>
void main( )
{ int s1,s2,num;
s1=s2=0;
for(x=0;x<11;x++)
{
cin<<num;
If(num>0)s1+=num;else s2=/num;
}
cout<<s1<<s2; }
Ans.13. The program will not execute successfully. Because some syntax errors are there in the program. They are
(i) cin and cout, stream objects used but iostream.h header file is not included in the program.
(ii) x is not declared, it should be declared as int.
(iii) With cin, we should use >> instead of <<.
(iv) The shorthand operator /=, is given wrongly as =/.
So the corrected program is as follows:
#include<iostream.h>
void main( )
{ int s1,s2,num;
s1=s2=0;
for(int x=0;x<11;x++)
{
cin>>num;
if(num>0)s1+=num;else s2/=num;
}
cout<<s1<<s2; }
Q.14. Identify the errors if any. Also give the reason for errors.
#include<iostream.h>
void main()
{
const int i =20;
const int * ptr=&i;
(*ptr)++;
int j=15;
ptr =&j;
}
Ans.14. #include<iostream.h>
void main()
{
const int i=20;
int * ptr=&i;
(*ptr)++; //can not modify a const object
int j=15;
ptr =&j;
}
15. Identify the errors if any. Also give the reason for errors.
#include<iostream.h>
void main()
{
const int i =20;
const int * const ptr=&i;
(*ptr)++;
int j=15;
ptr =&j;
}
Ans.15. #include<iostream.h>
void main()
{
const int i =20;
const int * const ptr=&i; //can not modify a const object
(*ptr)++;
int j=15;
ptr =&j; //can not modify a const pointer
}
Q.16. Identify errors on the following code segment
float c[ ] ={ 1.2,2.2,3.2,56.2};
float *k,*g;
k=c;
g=k+4;
k=k*2;
g=g/2;
cout<<”*k=”<<*k<<”*g=”<<*g;
Ans.16. The error statements are
k=k*2; g=g/2; as pointer multiplication and division is not possible.
Q.17.. Write the output of the following program. 2
void main( )
{
int x=5,y=5;
cout<<x- -;
cout<<”,”;
cout<- - x;
cout<<”,”;
cout<<y- -<<”,”<<- -y;
}
Ans.17. 5,3,4,4
Q.18. Predict the output of the following code:
# include<iostream.h>
#include<conio.h>
void main()
{
int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *ptr++; cout << val << endl;
val = *ptr; cout << val << endl;
val = *++ptr; cout << val << endl;
}
Ans.18. int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *ptr++; cout << val << endl; // first print value then increment the
address(post
// increment in value)
val = *ptr; cout << val << endl; // only values are changing
val = *++ptr; cout << val << endl; // first increment the address and then print the
value.
}
Coding only for explanation. Don’t write coding in answer
t. Write only the correct output.
12
12
23
34
Q.19. Find the output of the following code.
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *ptr++; cout << val << endl;
val = *ptr; cout << val << endl;
val = *++ptr; cout << val << endl;
val = ++*ptr; cout << val << endl;
}
Ans.19. int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *ptr++; cout << val << endl; // first print value then increment the address(post
//increment in value)
val = *ptr; cout << val << endl; // only values are changing
val = *++ptr; cout << val << endl; // first increment the address and then print the
value.
val = ++*ptr; cout << val << endl;
}
12
12
23
34
35
Q.20. . #include<iostream.h>
#include<conio.h>
void main()
{
int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = (*ptr)++; cout << val << endl;
val = *ptr; cout << val << endl;
val = *++ptr; cout << val << endl;
}
Ans.20.
int arr[] = {12, 23, 34, 45};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = (*ptr)++; cout << val << endl; // (post increment in value)
val = *ptr; cout << val << endl; // only values are changing
val = *++ptr; cout << val << endl; // first increment the address and then print the
//value.
}
12
12
13
23
Q.21. #include<iostream.h>
#include<conio.h>
void main()
{
int arr[] = {2, 33, 44, 55};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *++ptr ; cout << val << endl;
val = *ptr; cout << val << endl;
val = * ptr++; cout << val << endl;
}
Ans.21. int arr[] = {2, 33, 44, 55};
int *ptr = arr;
int val = *ptr; cout << val << endl;
val = *++ptr ; cout << val << endl;
val = *ptr; cout << val << endl;
val = * ptr++; cout << val << endl;
}
2
33
33
33
Q.22. Write the output of the following program:
#include<iostream.h>
#include<conio.h>
void main( )
{
clrscr( );
int a =32;
int *ptr = &a;
char ch = ‘A’;
char *cho=&ch;
cho+=a; // it is simply adding the addresses.
*ptr + = ch;
cout<< a << “” <<ch<<endl;
}
Ans.22. 97A
Q.23. Write the output of the following program:
#include<iostream.h>
#include<conio.h>
void main( )
{
clrscr( );
int a =32;
int *ptr = &a;
char ch = ‘A’;
char *cho=&ch;
*cho+=a; // it is adding the values.
cout<< a << “” <<ch<<endl;
}
Ans.23. The meaning of line *cho+=a is:
*cho= *cho +32
= A+32
=97
=’a’ ( ASCII value of character a)
cho contains the address of ch so ch =’a’;
Therefore output would be : 32a
Q.24. Write the output of the following program:
#include<iostream.h>
#include<conio.h>
void main( )
{
clrscr( );
int a =32;
int *ptr = &a;
char ch = 'A';
char *cho=&ch;
*cho+=a;
*ptr += ch;
cout<< a << "" <<ch<<endl;
}
Ans.24. 129a
ch =97 ( from *cho+=a)
*ptr+=ch
*ptr= *ptr+ch
= 32+ ‘a’ (Character a)
=32+97
=129
Since *ptr or variable a both are same so variable a =129 and ch = ‘a’.
Q.25. Write a function in C++ to print the count of the word the as an independent
word in a text file STORY.TXT.
For example, if the content of the file STORY.TXT is
There was a monkey in the zoo.
The monkey was very naughty.
Then the output of the program should be 2.
Ans.25. void thewordCount()
{
ifstream Fil(“STORY.TXT”);
char String[20];
int C=0;
while(Fil)
{
Fil>>String;
if(strcmpi(String,”the”)==0)//case insensitive
C=C+1;
}
cout<<C<<endl;
Fil.close();
}
OR
void thewordCount()
{
ifstream Fil(“STORY.TXT”);
char String[20];
int C=0;
while(Fil)
{
Fil>>String;
if(strcmp(String,”the”)==0 || strcmp(String,”The”)==0)
C=C+1;
}
cout<<C<<endl;
Fil.close();
}
OR
void thewordCount()
{
ifstream F(“STORY.TXT”);
char Str[4];
int C=0;
while(F.getline(Str,4,’ ‘))
{
if(strcmp(Str,”the”)==0 || strcmp(Str,”The”)==0)
C=C+1;
}
cout<<C<<endl;
F.close();
}
Q.26. Assume a text file “coordinate.txt” is already created. Using this file create a C++function to count the number of words having first character capital. Example:
Do less Thinking and pay more attention to your heart. Do Less Acquiring and pay more Attention to what you already have. Do Less Complaining and pay more Attention to giving. Do Less criticizing and pay more Attention to Complementing. Do less talking and pay more attention to SILENCE. Output will be : Total words are 16
Ans.26. Hint: Use isupper(word[0])
Q.27. Write a function in C++ to count the number of lines present in a text file
“STORY.TXT”.
Ans.27. void CountLine()
{
ifstream FIL(“STORY.TXT”);
int LINES=0;
char STR[80];
while (FIL.getline(STR,80))
LINES++;
cout<<”No. of Lines:”<<LINES<<endl;
FIL.close();
}
Q.28. Write a function in C++ to count the number of alphabets present in a text file
“NOTES.TXT”.
Ans.28. void CountAlphabet()
{
ifstream FIL(“NOTES.TXT”);
int CALPHA=0;
char CH=FIL.get();
while (FIL)
{
if (isalpha(CH)) CALPHA++;
CH=FIL.get();
}
cout<<”No. of Alphabets:”<<CALPHA<<endl;
FIL.close();
}
Q.29. Write a function in C++ to write the characters entered through the keyboard into the file“myfile.txt”, until a ‘#’ character is entered.
Ans.29. void entercharacter{
ofstream fout;
fout.open("string.txt");
if(!fout) {
cout<<"\n Unable to open file";
exit(1);
}
char c;
while((c=cin.get())!='#') // or while((c=getchar())!= ‘#’)
{
fout.put(c);
}
fout.close();
}
Q.30. Answer the questions (i) and (ii) after going through the following class:
class Seminar
{
int Time;
public:
Seminar() //Function 1
{
Time=30;cout<<"Seminar starts now"<<end1;
}
void Lecture() //Function 2
{
cout<<"Lectures in the seminar on"<<end1;
}
Seminar(int Duration) //Function 3
{
Time=Duration;cout<<"Seminar starts now"<<end1;
}
~Seminar()
//Function 4
{
cout<<"Vote of thanks"<<end1;
}
};
i) In Object Oriented Programming, what is Function 4 referred as and when does it get
invoked/ called?
ii) In Object Oriented Programming, which concept is illustrated by Function 1 and Function 3 together? Write an example illustrating the calls for these functions.
Ans.30. i) Destructor, it is invoked as soon as the scope of the object gets over.
ii) Constructor Overloading (or Function Overloading or Polymorphism)
Seminar S1; //Function 1
Seminar S2(90); //Function 3
Q.31. Answer the questions (i) and (ii) after going through the following program
#include<iostream.h>
#include<string.h>
class Bazar
{
char Type[20];
char Product[20];
int Qty;
float Price;
Bazar() //Function 1
{
strcpy (Type,”Electronic”);
strcpy (Product,”Calculator”);
Qty = 10;
Price=225;
}
public:
void Disp( ) //Function 2
{
cout<<Type<<”-“<<Product<<”:“<<Qty
<<”@“<<Price<<endl;
}
};
void main( )
{
Bazar B; //Statement 1
B.Disp(); //Statement 2
}
(i) Will Statement 1 initialize all the data members for object B with the values given in the Function 1? (Yes OR No). Justify your answer suggesting the correction(s) to be made in the above code.
(ii) What shall be the possible output when the program gets executed?
(Assuming, if required – the suggested correction(s) are made in the
program)
Ans.31.
(i) No, since the constructor Bazar has been defined in private section or constructor has not been defined in public section. Suggested Correction: Constructor Bazar() to be defined in public
(ii)If the constructor is defined as a public member, the following output shall be generated:
Electronic-Calculator:10@225
Q.32. Given a class as follows:
class Match
{
int Time;
int Points;
public:
Match(int y, int p) //Conctructor1
{
Time=y;
Points =p;
}
Match(Match &M); // Constructor 2
};
(i) Create an object, such that it invokes Constructor 1.
(ii) Write complete definition for Constructor 2.
Ans.32. (i) Match M1(0,0);
(ii) Match (Match &M)
{
Time=M.Time;
Points=M.Points;
}
Q.33. Answer the questions (i) and (ii) after going through the following class:
class player
{
int health;
int age;
public:
player() { health=7; age=17 } //Constructor1
player(int h, int a) {health =h; age = a ; } //Constructor2
player( player &p) { } //Constructor3
~player() { cout<<”Memory Free”; } //Destructor
};
void main(){
player p1(9,26); //Statement1
player p3 = p1; //Statement3
}
(i) When p3 object created specify which constructor invoked and why?
(ii) Write complete definition for Constructor3?
Ans.33. (i)When p3 object created , Constructor 3 will be invoked since it is copy
constructor.
(ii) complete definition for Constructor 3
player( player &p)
{
health = p.health;
age= p.age;
}
34.. Assume a text file “Test.TXT” is already created. Using this file, create a function to create three files “LOWER.TXT” which contains all the lowercase vowels and UPPER.TXT” which contains all the uppercase vowels and “DIGIT.TXT” which contains all digits.
35. Assume that a text file named text1.txt already contains some text written into it, write a function named vowelwords(), that reads the file text1.txt and create a new file named text2.txt, which shall contain only those words from the file text1.txt which don’t start with an uppercase vowel(i.e., with ‘A’,’E’,’I’,’O’,’U’). for example if the file text1.txt contains:
Take One Apple And one glass milk daily.
Then the file text2.txt shall contain :
Take one glass milk daily.
36. Assume a text file “Test.TXT” is already created. Using this file, create a function to create three files “LOWER.TXT” which contains all the lowercase vowels and UPPER.TXT” which contains all the uppercase vowels and “DIGIT.TXT” which contains all digits.
37. Write a function in C++ to calculate the average word size in a text file “Report.txt”, each word is separated by single space or full stop.
38. Create a function FileLowerShow() in c++ which take file name(text files)as a argument and display its all data into lower case.
HOTS for Programming in C++ Computer Science Class 12
Expert teachers of studiestoday have referred to NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 HOTS. If you download HOTS with answers for the above chapter you will get higher and better marks in Class 12 test and exams in the current year as you will be able to have stronger understanding of all concepts. High Order Thinking Skills questions practice of Computer Science and its study material will help students to have stronger understanding of all concepts and also make them expert on all critical topics. You can easily download and save all HOTS for Class 12 Computer Science also from www.studiestoday.com without paying anything in Pdf format. After solving the questions given in the HOTS which have been developed as per latest course books also refer to the NCERT solutions for Class 12 Computer Science designed by our teachers. We have also provided lot of MCQ questions for Class 12 Computer Science in the HOTS so that you can solve questions relating to all topics given in each chapter. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter
You can download the CBSE HOTS for Class 12 Computer Science Programming in C++ for latest session from StudiesToday.com
Yes, the HOTS issued by CBSE for Class 12 Computer Science Programming in C++ have been made available here for latest academic session
HOTS stands for "Higher Order Thinking Skills" in Programming in C++ Class 12 Computer Science. It refers to questions that require critical thinking, analysis, and application of knowledge
Regular revision of HOTS given on studiestoday for Class 12 subject Computer Science Programming in C++ can help you to score better marks in exams
Yes, HOTS questions are important for Programming in C++ Class 12 Computer Science exams as it helps to assess your ability to think critically, apply concepts, and display understanding of the subject.