CBSE computer and communication technology

Sponsor Area

Question
CBSEENCO12011710

Give the difference between the Type Casting and automatic Type Conversion. Also, give a suitable C++ code to illustrate both.

Solution

Type Casting Automatic Type Conversion
Type Casting is used to convert the value of one type to another type. Automatic Type Conversion is the type conversion done by the compiler wherever required.
For example,
float x = (float)3/2;
//1.5 will be assigned as result, because 3 is converted into 3.0
For example,
float x = 3/2;
// here 1.0 will be assigned as result, because 1 is automatically converted in 1.0

Sponsor Area

Question
CBSEENCO12011711

Which C++ header file(s) are essentially required to be included to run/execute the following C++ source code (Note: Do not include any header file, which is/are not required);

Void main()
{
	char TEXT[] = 'SomeThing';
	cout<<'Remaining SMS Chars:'
	<<160-strlen(TEXT)<< endl;
}

Solution

Header file required to execute C++ program are -
(i) iostream.h
(ii) string.h

Question
CBSEENCO12011712

Rewrite the following program after removing the syntactical error(s) (if any). Underlie each correction.

#include<iostream.h>
Class Item
{
	long IId,Qty;
public:
	void Purchase
	{
		cin>>IId>>Qty;
	}
}	void Sale()
{
	cout<<setw(5)<<IId<<'Old:'<<Qty<<endl;
	cout<<'New:'<<--Qty<< endl;
}
void main()
{
	Item I;
	Purchase();
	I.Sale();
	I.Sale(0)
}

Solution

#include<iostream.h>
#include<iomanip.h>
class Item
{
long IId,Qty;
public:
void Purchase()
{
cin>>IId>>Qty;
}
} void Sale()
{
cout<<setw(5)<<IId<<'Old:'<<Qty<<endl;
cout<<'New:'<<--Qty<< endl;
};
void main()
{
Item I;
I.Purchase();
I.Sale();
I.Sale(0);
}

Question
CBSEENCO12011713

Find the output of the following program:

#include<iostream.h>
class METRO
{
	int Mno, TripNo,PassengerCount;
public:
	METRO (int Tmno=1)
	{
		Mno=Tmno;TripNo=0;PassengerCount=0;
	}
	void Trip(int PC=20)
	{
		TripNo++;PassengerCount+=PC;
	}
	void StatusShow()
	{
		cout<<Mno<<':'<<TripNo<<':'<<PassengerCount<<endl;
	}
};
	void main()
	{
		METRO M(5),T;
		M.Trip();
		T.Trip(50);
		M.StatusShow();
		M.Trip(30);
		T.StatusShow();
		M.StatusShow();
	
	}

Solution

Output of the given code:

5:1:20
1:1:50
5:2:50

Question
CBSEENCO12011714

Find the output of the following program:

#include<iostream.h>
#include<c.type.h>
typeof char Str80[80];
void main()
{
	char*Notes;
	Str80 Str='vR2GooD':
	int L = 6;
	Notes =Str;
	while(L>=3)
	{
		Str[L]=(isupper(Str[L])?tolower(Str[L]):toupper(Str[L]));
		cout<<Notes<<endl;
		L--;
		Notes++;
	}
}

Solution

The output of the following program:

vR2Good
R2GoOd
2GOOd
gOOd