0% found this document useful (0 votes)
3 views8 pages

Programming Fundamentals Using c++ 2534

This document is a question paper for a course on Programming Fundamentals Using C++, covering topics such as identifiers, data types, pointers, and C++ programming concepts. It consists of multiple sections, including compulsory questions and optional questions, with a total of 90 marks available. The paper includes programming tasks, theoretical questions, and code analysis, aimed at assessing students' understanding of C++ programming.

Uploaded by

bocosa7990
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)
3 views8 pages

Programming Fundamentals Using c++ 2534

This document is a question paper for a course on Programming Fundamentals Using C++, covering topics such as identifiers, data types, pointers, and C++ programming concepts. It consists of multiple sections, including compulsory questions and optional questions, with a total of 90 marks available. The paper includes programming tasks, theoretical questions, and code analysis, aimed at assessing students' understanding of C++ programming.

Uploaded by

bocosa7990
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/ 8

This question paper contains 8 printed pages]

oe · DI, 5U)2S ( E~
S. No. of Question Paper : 2534 I I I I I I I I 1,r I J
Unique Paper Code
: 2342571101
Name qf the Paper
: · Programming Fundamentals Using C++
Name of the Course
: B.A. (Prog.)/B.Sc.(P)IB.Sc. Maths. Sc.
Semester
: I
Duration : 3 Hours

Maximum Marks : 90
(Write your Roll No. on the top immediately on receipt of this question paper.) .

Section A is compulsory.

Attempt any 4 (four) questions from Section B.

....
~
All parts of a question must be answered together.
J
Section A

I. (a) What are identifiers in C++ ? Identify which of the following identifiers are valid and
which are invalid ?.

(i) 3
Po178 ddm

(ii)
-78hhvt4
(iii) 902gt1

(iv) Tyy;ui8

(v) For

(vi) Fg026 neo

P.T.O.
2534
( 2 )
3

(b} Explain the following :

(i) Built-In data Types

(iz) User defined data types

(iii) Derived data types


(c) Explain pointers in Ct+ With an example. How does a pointer differ from a regular
3

variable? 3
(d) Write the output of the following C++ code :

#include <iostream>

using namespace std;

int main() {

int numl = 10;

double num2 = num 1;


cout << "numl: "<< nurnl << endl;

cout << "num2: "<< num2 << endl;

retum O;.

} 3
(e) Write a C++ program to find largest of 2 numbers.
3
(j) Find the output of the following C++ code :

#include <iostream>

using namespace std;

int main() {

int a = 15, b = 4;
( 3 )
2534
int result!= a/b * b +a% b;

bool result2 = (a = = 15) && (b < 10);

int resu1t3 = a++ + - -b;

int resu1t4 = 10 + 2 * 3 / 4 - 5;

cout << "Result 1: " << result! << endl;

cout << "Result 2: " << result2 << endl;

cout << "Result 3: " << result3 << endl;

cout << "Result 4: " << result4 << endl;


return O;

(g) Which of the following statements is true or false :


3
(i) A constructor is automatically invoked on object creation, cannot have a return
type-not even void, and does not return any value .

. (ii) A destructor is a member function that is specifically called on an object by a


programmer when the object goes out of scope.

(iii) The constructor can be overloaded. That is, you can have more than one
constructor in a class having different parameter lists.

(h) Write a C-H- program to ensure that a user enters a positive integer. Initially, the program
should ask the user for a number. If the user enters a number less than or equal to
zero, the program should keep asking until a valid positive number is provided. 3
(i) Differentiate between single and multiple inheritance.
3

P.T.O.
\

2534
( 4 )

(j) Identify the error in the following Try-Catch block and correct the same : 3

.int main() {

int a = 10, b = O;

try {

if (b == 0) {

throw "Division by zero error!";

} else {

cout << "Result: " << a / b << endl;

} catch (int e) {

cout << "Error: Division by zero!" << endl;

return 0;

}
Section B

2. (a) Write a C++ program that takes a positive integer n and produces n lines of output

as shown : (n = 4 as output) : 5

1 2

1 2 3

1 2 3 4
( 5 )
2534

(b) Explain the following jump statements with the help of an example :
5
· (i) break

(ii) continue

(iii) return

(c) What do you mean by header files in C++ ? How do header files reduce the compilation
time and efforts of the programmer ? How do you include a header file in a C++
~gram? 5

3. (a) Write a C++ program that uses a for loop to compute the sum of the first n natural
numbers. Prompt the user to input a value for n; print out the sum. 5

(b) Write a C++ program to _take an integer as an input, reverse the digits of that integer
and print -that reversed integer. 5

(c) Write a C++ program that prints the Fibonacci sequence up to the nth term. The
program should ask the user to enter the value of n, then print the first n Fibonacci
numbers. 5

4. (a) Which of the following statements is true or false :


5
(i) In C++, a pointer may be assigned the address of a variable of any type without
any problem.

(ii) The * stands for address of the pointer variable.

(iii) You can increment a pointer to point at the next memory location of the type that
it is pointing at.

(iv) A pointer can be dereferenced before it is declared, and the program will still run
with no issues.

(v) In C++, delete is used to free up memory which was allocated using maIIoc( ).

P.T.O.
2534
( 6 )

(b) Write a C++ program simulating a simple Shape hierarchy. Declare a base class called
Shape with a virtual function area( ). Derive two classes, Circle and Rectangle,
each overriding the area( ) function to calculate the area of a circle and a rectangle
respectively. Program Jo ask for all inputs necessary-for example, the radius for the
circle and the length and width for the rectangle. Then calculate the area and print the
5
results.
5
(c) · Enumerate any jive characteristics of object-oriented programming.

5. (a) What will be the output of the following code when the value of num is : 5 ·

(i) 1

(ii) 67

(iii) 2

(iv) A and

(v) default

#include <iostream>

using namespace std;

int main() {

switch (num) {

case 1: .

cout << "One" << endl;

case 2:

cout << "Two" << endl;

break;
( 7 )
2534

case 3:

cout << "Three" << endl;

break;

case 4:

cout << "Four" << endl;

break;

default:

cout << "Invalid" << endl;

return O;.

(b) What are default constructors in C++ ? Explain with an example.


5
(c)
What is constructor overloading ? Explain with the help of an example.
5
6. (a)
Write a C++ program for a library system that stores the details of books in an array.
Each book has the following information : 5

• Title (a string)

• Author (a string)

• Year of publication (an integer)

You are given an array of pointers, each pointing to a dynamically allocated object of
type Book. The user can add new books to the system, display the information of all
the books, and delete a book when it is no longer needed.

P.T.O.
( 8 )
2534

(b) · Write a C++ program that swaps the values of two integers using pointers. Create a

function swapValues( ) thattakes two integer pointers and swaps the values they point

to. In main( ), declare two integers, pass their addresses to the function, and display

their values before and after the swap. Use pointers to directly manipulate the variable
5
values.

(c) Identify whether the following pointer declarations are valid or invalid. Explain your
5
answer.

(z) char* ptr =; &someCharVariable;

(ii) int* ptr, ptr2;

(iii) float* ptr = new float;

(iv) int** ptrl;

(v) double ptr*;


15
7. Explain the following :

(i) Function Overloading

(ii) Arrays in C++

(iii) Inheritance.

8
2534

You might also like