0% found this document useful (0 votes)
8 views4 pages

Solution_CS3201_OOPS_MidSem

This document is a mid-term examination paper for the MCA program at the National Institute of Technology Jamshedpur, focusing on Object Oriented Programming using C++. It includes various programming questions that require students to write C++ code for specific tasks, such as using loops, functions, and classes. The exam is structured with multiple questions, each assessing different programming concepts and techniques.

Uploaded by

cglssc787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Solution_CS3201_OOPS_MidSem

This document is a mid-term examination paper for the MCA program at the National Institute of Technology Jamshedpur, focusing on Object Oriented Programming using C++. It includes various programming questions that require students to write C++ code for specific tasks, such as using loops, functions, and classes. The exam is structured with multiple questions, each assessing different programming concepts and techniques.

Uploaded by

cglssc787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

National Institute of Technology Jamshedpur

Department of Computer Science and Engineering

SOLUTION - Mid-Term Examination of Spring Semester 2024-2025


Branch: MCA (Computer Science and Engineering)
Course Code and Name: CS 3201 Object Oriented Programming using C++ Max. Marks: 30

Course Faculty: Dr. Deepak Rai

Q1 Write individual statement for the following: 1*5


(i) that displays the variable name in a field 10 characters wide.
=5
cout << setw(10) << name;
(ii) that uses an arithmetic assignment operator to increase the value of the variable temp
by 23.
temp += 23;
(iii) that uses a conditional operator to set ticket to 1 if speed is greater than equal to 55,
and to 0 otherwise.
ticket = (speed >= 55) ? 1 : 0;
(iv) that prints yes if a variable ch is ‘y’, prints no if ch is ‘n’ and prints unknown response
otherwise using switch-case.
switch(ch)
{
case ‘y’:
cout << “yes”;
break;
case ‘n’:
cout << “no”;
break;
default:
cout << “unknown response”;
}
(v) that declares an enumerated data type called speeds with the values fast, moderate,
and slow. Give these three names the integer value 78, 45, and 33.
enum speeds {fast=78, moderate=45, slow=33};

Q2 Assume there are 2.20462 pounds in a kilogram, write a C++ program that asks the user to enter 3
number of pounds, and then display the equivalent in kilogram
int main()
{
float pound, kg;
cout << “\n Enter quantity in pounds: ”;
cin >> pound;
kg = pound / 2.20462;
cout << “\n Equivalent in Kg is: ” << kg;
return 0;
}

3
Q3 Write a C++ program that prints following: 10 20 19. Use an integer constant for the 10, an
arithmetic assignment operator to generate the 20, and a decrement operator to generate the 19.
int main()
{
int var = 10;
cout << var << “ ”;
var *= 2;
cout << var-- << “ ” ;
cout << var << “ ” ;
return 0;
}

Q4 Write a for loop, while loop, and do-while loop using C++ program that displays the numbers 5
from 112 to 123 except 117.
***** For-loop *****

for(int i =112; i<=123; i++)


{
if(i==117)
continue;
cout<<i<<endl;
}

****** While-loop ******

int i = 112;
while(i<=123)
{
if(i==117)
{
i++;
continue;
}
cout<<i<<endl;
i++;
}

***** Do-while-loop ****

int i = 112;
do
{
if(i==117)
{
i++;
continue;
}
cout<<i<<endl;
i++;
}while(i<=123);
3
Q5 Write the syntax for function declaration. What is the significance of empty parentheses in a
function declaration? Also tell how many values can be returned from a function.
***** Function declaration

return-type function-name (arguments);

**** Empty parentheses mean the function takes no arguments.

**** Only one value can be returned from a function.

Q6 Assume the following function definition: int Demo (int a ) { return (a*2); } 3
Write a main () program in C++ that includes everything necessary to call this function.
int main()
{
int Demo (int);
int x = Demo (37);
return 0;
}

Q7 Create a class time that has separate int member data for hours, minutes, and seconds. One 8
constructor should initialize this data to 0, and another should initialize it to fixed values. A member
function should display it, in 11:59:59 format. The final member function should add two objects of
type time passes as arguments. A main () program in C++ should create two initialized time
objects, and one that is not initialized. Then it should add the two initialized values together, leaving
the result in the third time variable. Finally, it should display the value of this third variable.
class time
{
int hours, minutes, seconds;
public:
time()
{
hours = 0; minutes = 0; seconds = 0;
}
time(int h, int m, int s)
{
hours = h; minutes = m; seconds = s;
}
void display()
{
cout<<hours<<":"<<minutes<<":"<<seconds;
}
void add_time(time t1, time t2)
{
seconds = t1.seconds + t2.seconds;
if(seconds > 59)
{
seconds -= 60; minutes++;
}
minutes += t1.minutes + t2.minutes;
if(minutes > 59)
{
minutes -= 60; hours++;
}
hours += t1.hours + t2.hours;
}
};
int main() {
time T1(5,59,59);
time T2(4,30,30);
time T3;

T3.add_time(T1, T2);
cout<<"\n Time = ";
T3.display();
return 0;
}

********************END OF THE EXAM*****************************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy