Documente Academic
Documente Profesional
Documente Cultură
Instructor Inputs
1.2 Installing Windows XP Professional NIIT
Solutions to Exercises
This session includes exercises for Chapter 2.
Chapter 2
Exercise 1
You have defined an Employee class as part of developing a software application for Diaz
Telecommunications Inc. The class, which you’ve defined, is as follows:
class Employee
{
char firstName;
char lastName;
char dateOfBirth;
char dateOfJoining;
char city;
char phoneNo;
public:
void accept()
{
//Code to accept employee details
}
void display()
{
//Code to display employee details
}
}
The Employee class definition shown above contains errors and is incomplete. Identify
and fix the errors. Complete the code in the Employee class definition and write the
main() function. Compile and execute the code.
Solution
The solution for this exercise is given in the TIRM CD:
Identify the classes and objects involved in the above scenario and their attributes. Write
methods in the class to accept and display the values of the different attributes.
Solution
The solution for this exercise is given in the TIRM CD:
Exercise 3
Predict the output of the following code:
#include <iostream>
void main()
{
char ch=’A’;
char ch1=66;
int i=60.00;
cout<<ch<<endl<<ch1<<endl<<i;
}
Solution
The output of the preceding code will be:
60
Solution
The output of the preceding code if the user has entered 12 will be:
Additional Exercises
Exercise 1
The following program should interchange the values of two variables var1 and var2 and
should print the new values of the variables. However, the program does not generate the
desired output. Identify the error in the program and write the correct code:
#include<iostream>
class interchange
{
private:
int var1;
int var2;
int temp;
void swap()
{
var1=5;
var2=10;
temp=var1;
var1=var2;
Solution
The solution for this exercise is given in the TIRM CD: