pk+l pk+l. n

21
# L-1IT -2/CSE Date: 24/0112021 BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA Ll/T -2 B. Sc. Engineering Examinations (January 2020 Term) Sub: CSE 103 (Discrete Mathematics) Full Marks: 180 Section Marks: 90 Time: 2 Hours (Sections A + B) USE SEPARATE SCRIPTS FOR EACH SECTION The figures in the margin indicate full marks. SECTION-A There are FOUR questions in this section. Answer any THREE. a Joey learned the concept of Mathematical Induction from Chandler. Now, Joey has (10) come up with a proof of the 'fact' that for all values of n, n + 3 = n + 7. He wrote the following arguments using the concept of mathematical induction: Let P n be the statement that n +3 = n +7. We will prove that Pn is true for all n E N. Assume, for induction that Pk is true. That is, k + 3 = k + 7. We must show that Pk+l is true. Now since k +3 = k +7, adding 1 to both sides we get k +3+1 = k +7+1. After regrouping we easily get (k+1) +3 = (k+1) +7. But this is simply Pk+l. Thus by the principle of mathematical induction Pn is true for all n E N. .. , Chandler is baffled with the proof. Help Chandler find out the flaws (if any) in the above arguments and explain the issue(s) elaborately. b You have bought something with Xtaka from a shop and need to pay the money. (20) You have one bundle of 2 taka notes and another bundle of 5 taka notes and you have more than X taka with you. But the problem is that the shop-keeper only accepts the exact amount, i.e., he will only accept Xtaka. You are not sure whether you can make the exact amount with your two bundles of notes. You called your genius little brother for help and he proved to you that if X 2: 4, then you don't need to worry about it at all. You need to provide the proof i) using strong induction and also ii) using weak induction. 2 a How many 4 digit numbers are there with at least one 7 when leading zeroes are not (8) allowed. b How many 4 digit numbers divisible by 11 are not palindromes? A palindromic (14) number is a number that remains the same when its digits are reversed (e.g., 1221). c Suppose, each note has a code number of length 8 with a 2-letter code followed by (8) a 6-digit serial number (the serial number may contain leading zeros). Now a note is called defective if there are repeated letters or some digit appears more than once

Upload: others

Post on 16-Mar-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

#

L-1IT -2/CSE Date: 24/0112021

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

Ll/T -2 B. Sc. Engineering Examinations (January 2020 Term)

Sub: CSE 103 (Discrete Mathematics)

Full Marks: 180 Section Marks: 90 Time: 2 Hours (Sections A + B)

USE SEPARATE SCRIPTS FOR EACH SECTION

The figures in the margin indicate full marks.

SECTION-A

There are FOUR questions in this section. Answer any THREE.

a Joey learned the concept of Mathematical Induction from Chandler. Now, Joey has (10)

come up with a proof of the 'fact' that for all values of n, n + 3 = n +7. He wrote the

following arguments using the concept of mathematical induction:

Let Pn be the statement that n + 3 = n +7. We will prove that Pn is true for all n E N.

Assume, for induction that Pk is true. That is, k + 3 = k +7. We must show that Pk+l is

true. Now since k + 3 = k +7, adding 1 to both sides we get k + 3 +1 = k +7+1. After

regrouping we easily get (k+1) + 3 = (k+1) +7. But this is simply Pk+l. Thus by the

principle of mathematical induction Pn is true for alln E N ...,Chandler is baffled with the proof. Help Chandler find out the flaws (if any) in the

above arguments and explain the issue(s) elaborately.

b You have bought something with Xtaka from a shop and need to pay the money. (20)

You have one bundle of 2 taka notes and another bundle of 5 taka notes and you

have more than X taka with you. But the problem is that the shop-keeper only

accepts the exact amount, i.e., he will only accept Xtaka. You are not sure whether

you can make the exact amount with your two bundles of notes. You called your

genius little brother for help and he proved to you that if X 2: 4, then you don't need

to worry about it at all. You need to provide the proof i) using strong induction and

also ii) using weak induction.

2 a How many 4 digit numbers are there with at least one 7 when leading zeroes are not (8)

allowed.

b How many 4 digit numbers divisible by 11 are not palindromes? A palindromic (14)

number is a number that remains the same when its digits are reversed (e.g., 1221).

c Suppose, each note has a code number of length 8 with a 2-letter code followed by (8)

a 6-digit serial number (the serial number may contain leading zeros). Now a note is

called defective if there are repeated letters or some digit appears more than once

L-l/T -2/CSE

in the code, How common are non-defective notes?

Date: 24/0112021

3 a Sheldon asked his friends to deduce the truth values of the following statements:

i) If the 7624th digit of 1t is 8, then 2 + 2 = 4,

ii) If 8 is a prime number, then the 7624th digit of 1t is an 8,

Howard immediately started to write a program to find the 7624th digit of 1t, Leonard

does not think that is necessary at all. What is your opinion? If possible, deduce the

truth values of the statements or explain why it is not possible,

(6)

b Consider two types of people: Knights and Knaves, Knights always tell the truth and (24)

Knaves always lie, Now consider 2 persons, A and B, Figure out whether each

person is a knight or a knave from their statements as per the following table .

(Questions i-vi):

No, A Says: B Says:

i At least one of us is a knave <nothing>

ii The two of us are both knight A is a knave

iii I am a knave or B is a knight <nothing>

iv I am a knight I am a knight

v We are both knaves <nothing>

vi B is a knight The two of us are opposite types

4 a It is always possible to wiite r = min where r is a rational number and m, n integers (15)

without common prime factors, Now prove by contradiction that ";2 is irrational. [Any

other claim as pari of your proof must also be proved],

b Given that a and b are irrational, you teacher asked the question whether ab can be (10)

~ ..

•L-1IT -2/CSE Date: 2410112021

c

rational. Listening to.the question, your genius younger brother gave a crude smile

and said 'of course! don't you know that -)2 is irrational?' Do you agree with your

brother? Explain your answer.

Is 0.12121212 a rational number? (5)

t

L-Irr-2/CSE Date: 24/0112021

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

L-Irr-2 B. Sc. Engineering Examinations (January 2020 Tenn)

Sub: CSE 103 (Discrete Mathematics)

Full Marks: 180 Section Marks: 90 Time: 2 Hours (Sections A + B)

USE SEPARATE SCRIPTS FOR EACH SECTION

The figures in the margin indicate full marks.

SECTION-B

There arc FOUR questions in this section. Answer any THREE.

5.(a) A bus route is shown in the graph in Figure 5(a)-I. Find the adjaccncy list for the graph. (8)

Figure 5(a)-1

5. (b) Show that the graph in Figure 5(a)-1 has an Euler circuit. Find the Euler circuit startingfrom the node F. Show the steps. (l0)

5. (c) ((2+3)*(7-6*(8/4)+3»*2*(18/3) is an infix exprcssion. Build the binary trce from this infixcxpression. (For cxamplc, for 2+3, '+' will be in root, 2 will be the left child ahd 3 will be theright child.)

(4)5. (d) After building the tree (in Q. 5(b», find the postordcr traversal of the tree and what will bethe hcight of the trec? For a complete 3-ary trce what will be the total nodcs for a height 3?

(4+4=8)

6.(a) An alphabet sct A consists of the three numeric characters, J, 2, 3 and five alphabeticcharacters p, q, r, s, t. Deduce and solve the recurrence relation for the number of words (usingthe alphabet set A) of length k, wherc there are no consecutive (identical or distinct) alphabeticcharacters. (10)

6.(b) Find thc worst case and best case cost of a function maxJind (A(ill) that finds themaximum integer value from an array A of 11 integers. (6)

6.(c) Find thc properties of thc algcbraic structure <S, *> defined by the following table whereS={A. B.C. D,E, F) and * is the operator. Justify your answer. (14)

EJ)C

CJ)

BFA E

L-I/T -2/CSE Date: 24/01/2021

7.(a) Let S = {l, 2, 3, 4,5, 6), f S-7 R andf={(l, 7), (2,9), (3,11), (4,13), (5,15), (6,17)}. Letg: Q~R where g(q) = 2q+5 for all q in Q, h :R~R where h(r) = 2r+5 for all r in R. Show thatfis a restriction of function h (from R to S). (6)

7.(b) Find the relationship of the Stirling number of the second kind and the onto function in thecontext of finding two-factor and three-factor factorizations greater than J for the number156009. (12)

7.(c) For a program, CSE department starts sending invitations to the participants one monthbefore. At least one invitation has been sent each day but no more than 50 invitations have beensent in total. Show that there has been a specific consecutive period of days where exactly 11invitations have been sent. (12)

8.(a) Find the Hasse diagram for the divisibility on the set {l, 3, 9, 27, 81, 243). Show the steps.Find the maximal and minimal elements. (15)

8.(b) Find the smallest relation, R containing the relation RI={(I,2), (1,4), (3,3), (4,1)} such thatR is reflexive. symmetric and transitive. Explain your answer. (8)

8.(c) Determine whether the relation R on the set of all locations is reflexive/ symmetric!antisymmetric! transitive and justifY the answer, where R is defined as follows- for the locationsX and Y if and only if

i. everyone who has visited X, has also visited Y.ii. there are no conunon paths found on X and Y.iii. there is at least a common path on X and Y.iv. there is a location that includes path to both X and Y. (7)

I ~~,

,.' •

L-lrr-2/CSE Date: 17/0112021

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

.1~11T-2 B. Sc. Engineering Examinations (January 2020 Term)

Sub: CSE 107 (Object Oriented Programming Language)

Full Marks: 180 Section Marks: 90 Time: 2 Hours (Sections A + B)

USE SEPARATE SCRIPTS FOR EACH SECTION

The figures in the margin indicate full marks.

SECTION-A

There are FOUR questions in this section. Answer any THREK

All the questions in this section are related with C++ programming ianguage

I (a) A "Studcnt" class has a private variable to store 10, a constructor without parameter to initialize 10

and a private static variable. Write thc code scgmcnt for Class "Student" and to crcate an array of J 20

objects of "Student" class in the main function using 'new' operator. lOs of 120 "Student" objects are

initializcd in the constructor as 1,2, ... , 120, respectively. (10)

I(b) Explain what a default copy constructor generated by the compiler do and briefly describe a

circumstance where this wili cause a problem? (10)

1(c) Which feature ofC4+ programming language do you like most and why? The feature that you mention

should not be also a feature ofC programming language. (10)

2(a) Differentiate bctween function overloading and function overriding. (8)

2(b) If you overload operator+, you must return an object of the same type as your parameters. Do you

agrce? Justify your answer. (7)

2(c) "There are sccnarios whcn a friend function is vcry useful for operator overloading"- support this

statement for the following class 'Rational' by writing a program that has to use friend function for operator

overloading. (15)

class Rational{

II numerator and denom inatoriot 0, d;public:

IIConstructor(s) to initialize nand dRationalO{

n=O;d=O;

}Rational(int a, int b){

n=a;d=b;

}

};

L-IIT-2/CSE Date: 17/0112021

3(a) Write an example program to explain the order of execution of constructor functions for multilevelinheritance and multiple inheritance. (15)

3(b) Differentiate between compile time polymorphism and run time polymorphism.

3(c) Describe a scenario when we cannot create an object ofa class.

4(a) What is wrong with the fol1owing statement?void func(int x = 99, int y);

4(b) Write three ways to declare an object of string class.

(8)

(7)

(5)

(8)

4(c) Given the fol1owing class declaration 'Date', overload the binary minus operator so that an expressionlike obl-ob2 will give the difference between the two Date objects in number of days, where obI and ob2are objects of Date class. For simplicity of calculation assume that al1months have 30 days. Als6 overloadleft shift operator so that an expression like cout«ob will print day~month-year (e.g., J 7-1-2021), whereob is an object of Date class. Include a mainO function where these operators wil1be used. (17)

class Date{int day, month, year;public:Date(int m, int d, int y){

day=d;month=m;year=y;

}

};

!rIff -2/CSE Date: 20/01121

Bangladesh University of Engineering and Technology, DhakaL1T2 B.Sc Engineemg Examinations of January 2020

Subject: Chern 113 (Chemistry 1)Full Marks: 180 Time: 2 hours

Figure in the margin indicate the full marksUse separate scripts for each section and upload in the LMS system separately

SECTION A(There are FOUR questions in the section. Answer any THREE)

1a. Scale formation in boiler pipe is nothing but the consequence of solubility of the 10gas in liquid-justi!}' the statement.

b. What are the different factors that control the solubility of solid in liquid? The 20effect of temperature on the solubility of solid in liquid can be applied for thedetermination ofheat of solution of the solute-justify.

2.a Show that the depression of freezing point is dependent on the concentration of 10the solute but independent of the nature of the solute.

b. Show the freezing point depression iiJ a phase diagram. To identi!}' a human 20hormone that controls metabolism by detennining its molar mass a saJl}pJeweighing 0.546 g was dissolved in 15.0 g benzene, and the freezing-pointdepression was detemlined to be 0.240 DC. Calculate the molar mass of thehormone. [freezing point depression constant, Kr for benzene is 5.120 C kg/mol]

3a. Adsorption is an important phenomenon to form the charge on the colloidal 10particles-justify with examples.

b. Zeta potential is very important. in different applications of colloids and 20nanoparticles. Show the drop in potential in a schematic diagram and explain thepotential change from surface to the bulk.

4a. Why the properties of nanoparticles are different from conventional materials. 15b. Discuss the importance of computational technology in drug delivery. 15

Page 10f2

SECTIONB(There are FOUR questions in the section. Answer any THREE)

5a: Point out three characteristic features in the photoelectric effect that cannot be 15explained on the basis of wave theory oflight. Provide a brief explanation of thosefeatures.

b. How is the concept of electron density being used to describe the position of an J 5electron in the quantum mechanical treatment of an atom?

6.a

b

The ionization energy of 02 is smaller than the ionization energy of atomic 0 ; the 15opposite is true for the ionization energies of N2 and atomic N. Explain thisbehavior in terms ofthe molecular orbital energy diagrams of 02 and N2.A compound of chlorine and fluorine, ClFn reacts at about 75°C with uraniummetal to produce uranium hexafluoride (UF6), and chlorine monofluoride (CIF)(g).A quantity of uranium produced 3.53 g of UF6 and 343 mL of CIF at 75°C and2.50 atm. What is the formula (n) of the compound? Describe the bonding in the. .molecule, using valence bond theory.

, "

7a. For years, chemists and physicists focused on enthalpy changes as a way to 9measure the spontaneity of a reaction. What arguments would you use to convincethem not to use this method?

b. Is the distance a person travels on a trip a state function? Why or why not?c. Describe how a swinging pendulum that slows with time illustrates the first law of

thermodynamics.

8a. Describe the forces that.'f.0rk efficiently to hold proteins in their most stable three- ] 5dimensional structures. Briefly explain the different ways in which the proteinsstructures could be unfolded.

b. How can computational chemistry be utilized to address the real world problems ] 5in chemistry? Briefly explain with specific examples.

L-lrr-2/CSE Date: 13/01/2021-------------

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

L-l/T-2 B.Sc. Engineering Examinations- January 2020

Sub: HUM 183 (English)

Full Marks: 180 Time 2 Hours

The Figures in the margin indicate full marks

USE SEPARATE SCRIPTS FOR EACH SECTION

There are 4 page(s) in this question paper.

SECTION -A

There are FOUR questions in this section. Answer any THREE questionsincluding Question No. I as compulsory.

I. Answer anyone of the following: (20)(i) How does Paul learn the great importance of money? Support your

answer with details from "The Rocking-Horse Winner".

(ii) What do you think is the theme of "Shooting an Elephant"? Give

reasons for your ans\ver.

2.

.,

(a) Explain with reference to the context anyone of the following:

(i) Most of the wood was so rotten that when they pulled, it broke up: but

some trunks came out in one piece.(ii) He went off feeling confused and, in a childish way, .Iooking for the

secret to 'luck'.

(15)

(b) Answer any two of the following: (20)(i) Who are the Protagonist and the Antagonist in "Shooting an Elephant"?

(ii) Discuss the role offate in the story "An Astrologer's Day."

(iii) Do you think Oscar and Basset1 were right to encourage Paul to

keep betting? Why or why not?

3.

4.

Amplify anyone of the following:

(i) Good management is better than good income.

(ii) A calm sea does not make a skilled sailor.

Write a precis of the following passage with a suitable title:

What has been the influence of political and social circumstances upon the

thoughts of eminel11 and original thinkers, and, conversely, what has been the

influence of these men upon subsequent political and social developments?

Two opposite errors, both common, are to be guarded against. On the one hand,

men who are more familiar with books than with affairs are apt to over-estimate

the inlluence of philosophers. When they see Some political party proclaiming

itself inspired by So-and-So's teaching, they think its actions are anributable to

So-and-So, whereas, not infrequently, the philosopher is only acclaimed

because he recommends what the party would have done in any case. Writers of

books, until recently, almost all exaggerated the effects of their predecessors in

the same trade. But conversely, a new error has arisen by reaction against the

old one, and this new error consists in regarding theories as almost .passive

products of their circumsta'nces, and as having hardly any inlluence at all upon

the course of events. Ideas, according to this view, are the froth on the source of

deep currents, which are determined by material and technical causes: social

changes are no more caused by thought than the flow of a river is caused by the

bubbles that reveal its direction to an onlooker. Perhaps the truth lies between

these two extremes. Between ideas and practical life, as everywhere else, there

is reciprocal interaction; to ask which is cause and which is effect is as futile as

the problem of the hen and the eggs. It would be wasteful to engage in a

discussion of this question. Fruitfully, we could consider historically one

important case of the general question, namely the development of liberalism

and its offshoots from the end of the nineteenth century to the present day.

(35)

(35)

•• ••

::;:3 =

... SECTlON'~-B

TI,ere are FOUR questions in this section. Answer Q. NO.5 and any TWO from the rest.

5. Read the passage and answer the following questions: (20)

The word 'nanotechnology' comes from putting together two words - nano and

technology. Nano is a Greek word meaning 'dwarf. These objects are

measured in nanometres which is 0.000000001 of a metre. Scientists write this

as 10.9(count the number of digits to the right of the decimal point). Nano

particles are too small to be seen with the naked eye. You need powerful

microscopes to see them. To put that scale in another context, the comparative

size of a nanometre to a metre is the same as that of a marble to the size of the

eanh. Molecules and atoms are nano panicles. They are the basic building

blocks that make up matter. These building blocks are a'Tanged in many ways

to create all living and non-living things. Technology is more difficult to define.

It is about how humans use knowledge to control their environment. This

knowledge is practical. Often it means using tools to make things or to solve

problems. Nanotechnology, then, is about making things or solving problems

using atoms and molecules. Scientists are now able to manipulate atoms and

molecules to make new and exciting shapes. They do this one atom or molecule

at a time. They have noticed that materials have different properties at the nano

scale when compared with larger s.cales. The colour and strength of the material

can be quite different. One example is a carbon nanotube. Scientists created a

carbon nanotube by rolling a sheet of graphite molecules into a tube. The

carbon nanotube is hundreds of times stronger than steel but only one-sixth the

weight. Nano particles are now found in many products including sunscreen,

paint and inkjet paper. TI,e use of nano panicles in sunscreen makes it rub on

clear. Nanotechnology promises big things. Scientists are predicting that it will

be used in many ways in the future. In. computers, memory chips and the

circuitry could be made using nano particles. This could make computers

smaller than the head of a pin. Small machines could be made with nano

panicles. In medicine, robots could be made out of nano particles. These

'nanobots' could be used to perform surgery within the human body by

travelling through blood vessels. They could look for and kill cancer cells.

6

7.

8.

=4 =

Nano particles could also be used to clean up pollution in oceans. On the other

hand, nanotechnology raises many issues. The potential dangers of nano

particles are not well understood. Some people are concerned about the danger

to human health. They fear.that nano particles, because they are so small, could

avoid the body's immune systems and move into cells creating a detrimental

effect. Others are concerned about the effect of releasing nano particles into the

environment.

Questions:

(i) Give a suitable title of the passage with justification.

(ii) How can particles at a nano scale be different from the same material at

a larger scale?

(ii i) What concerns do some people have about using nano p3lticles in

products?

(iv) Give the meanings of the following words and expressions:

nanotechnology, dwarf, nanobots, immune systems, detrimental.

(a) What is 'Business Correspondence' and how is it different from personal

correspondence?

(b) Write an 'adjustment letter' expressing regret and offering

replacement/suitable compensation in reply to a complaint/claim letter.

(Provide necessary details of your own).

(a) What are the differences between dialogue and monologue?

(b) Write a dialogue between two interview candidates who have come to

attend a job interview and waiting for their turns.

Write an essay on anyone of the following topics:

(i) Life Imprisonment or Death Penalty: Pros and Cons

(ii) Education in a post-COVID world

(10)

(25)

(10)

(25)

(35)

L-1ff-21CSE ,--- Date: 10/0112021BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

L-Iff-2 B..Sc. Engineering Examinations 2018-2019Sub: MATH 147 (Ordinary Differential Equations (ODE), Partial Differential Equations

(PDE) and Vector Calculus)Full Marks: 240 Time: 2 Hours

USE SEPARATE SCRIPTS FOR EACH SECTIONThe figures in the margin indicate full marks.Symbols used have their usual meaning.

SECTION-AThere are FOUR questions in this section. Answer any THREE.

I. (a) Solve the following differential equation:. d

x(1 ~ x');:; + y(2x' -1)= ax'

(20)

(20)(a)

(b) A tank contains 200 liters of fluid in which 30 grams of salt is dissolved. Brine (20)

containing I gram of salt per liter is then pumped into the tank at a rate of 4

Umin; the well-mixed solution is pumped out at the same rate. Find the number

of grams of salt in the tank at time t.

Solve the following higher order differential equations:

d2--1:+ y = eX sinx + xe2x

d.x2

2.

3.

(b)

(a)

(b)

Solve the differential equation

2 d2y dy Ix --+x--y=---

d.x2 d.x (x+l)A mass weighing 4 pounds is attached to a spring whose constant is 2 lblft. Themedium offers a damping force that is numerically equal to the instantaneousvelocity. The mass is initially released from a point I ji below the equilibriumposition with a downward velocity of 8 jils. Determine the time at which themass passes through the equilibrium position. Find the time at which the mass.attains its extreme displacement from the equilibrium position.

Solve: 2yd'y -3(dy)' -4)" =0.dx' dx

(20)

(20)

(20)

4. (a) Find the integral surface of (2J01+I)p-(z+2x2)q= 2(x-),z) which passes (20)

through the line x = l, Y = O.

(b) Find the complete integral and singular integral (if exist) of p - 3x' = q' - y . (20)

SECTION-B

There are FOUR questions in this section. Answer any THREE.

5.

6.

(a) Solve the partial differential equationa2z a2z. az az +2---- 3-+ 3- = xy+ eX Yax2 ay2 ax ay

(b) Solve the heat conduction equation by the method of separation of variables

au = 100 a'u 0 < x < 1, t > 0at ax2 '

u(O, t) = u(l, t) = 0u(x,.O) = sin2rrx - sinSrrx

(a) Show that(i) (a x b) . (b x c) x (c x a) = (a. b x C)2

(ii) (a x b) x (c x d) = b(a' c x d) - a(b' c x d)

(b) Find the unit tangent at the point where t = 2 on the curvex = t 2 + 1, y = 4t - 3, z = 2t2 - 6t.

(15)

(25)

(30)

(10)

7. (a) Find the values of the constants a, b, c so that the directional derivative of (15)0= axy2 +'byz + CZ2x3 at (I, 2, -1) has a maximum magnitude 64 in thedirection parallel to z-axis.

(b) Evaluate fffv V. FdV where F = yx2 i+ (xy2 - 3z4)j + (x3 + y3)k and (25)V is the region bounded by the sphere

x2 + y2 + Z2 = 16, Y ::; 0 and z 2: 0 .

8. State Stokes' theorem and verify the theorem for the vector function (40)F = (Z2 - l)i + (z + xy3)j + 6k taken over the portion ofx = 6 - 4y2 -4z2 infrontofx = -2. .

L-1/T-2/CSE Date: 17/01/2021

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

L-1/T-2 B. Sc. Engineering Examinations (January 2020 Term)

Sub: CSE 107 (Object Oriented Programming Language)

Full Marks: 180 Section Marks: 90 Time: 2 Hours (Sections A + B)

USE SEPARATE SCRIPTS FOR EACH SECTION

The figures in the margin indicate full marks.

SECTION – A There are FOUR questions in this section. Answer any THREE.

All the questions in this section are related with C++ programming language

1(a) A “Student” class has a private variable to store ID, a constructor without parameter to initialize ID

and a private static variable. Write the code segment for Class “Student” and to create an array of 120

objects of “Student” class in the main function using ‘new’ operator. IDs of 120 “Student” objects are

initialized in the constructor as 1, 2, …, 120, respectively. (10)

1(b) Explain what a default copy constructor generated by the compiler do and briefly describe a

circumstance where this will cause a problem? (10)

1(c) Which feature of C++ programming language do you like most and why? The feature that you mention

should not be also a feature of C programming language. (10)

2(a) Differentiate between function overloading and function overriding. (8)

2(b) If you overload operator+, you must return an object of the same type as your parameters. Do you

agree? Justify your answer. (7)

2(c) “There are scenarios when a friend function is very useful for operator overloading”- support this

statement for the following class ‘Rational’ by writing a program that has to use friend function for operator

overloading. (15)

class Rational { // numerator and denominator int n, d; public: //Constructor(s) to initialize n and d Rational() { n=0; d=0; } Rational(int a, int b) { n=a; d=b; } … };

L-1/T-2/CSE Date: 17/01/2021 3(a) Write an example program to explain the order of execution of constructor functions for multilevel inheritance and multiple inheritance. (15) 3(b) Differentiate between compile time polymorphism and run time polymorphism. (8) 3(c) Describe a scenario when we cannot create an object of a class. (7) 4(a) What is wrong with the following statement? (5)

void func(int x = 99, int y);

4(b) Write three ways to declare an object of string class. (8) 4(c) Given the following class declaration ‘Date’, overload the binary minus operator so that an expression like ob1-ob2 will give the difference between the two Date objects in number of days, where ob1 and ob2 are objects of Date class. For simplicity of calculation assume that all months have 30 days. Also overload left shift operator so that an expression like cout<<ob will print day-month-year (e.g., 17-1-2021), where ob is an object of Date class. Include a main() function where these operators will be used. (17) class Date{ int day, month, year; public: Date(int m, int d, int y){ day=d;

month=m; year=y;

} … };

L-1/T-2/CSE Date: 17/01/2021

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY, DHAKA

L-1/T-2 B. Sc. Engineering Examinations (January 2020 Term)

Sub: CSE 107 (Object Oriented Programming Language)

Full Marks: 180 Section Marks: 90 Time: 2 Hours (Sections A + B)

USE SEPARATE SCRIPTS FOR EACH SECTION

The figures in the margin indicate full marks.

SECTION B

There are FOUR questions in this section. Answer any THREE.

All the questions in this section are related with Java programming language

5(a). What is the difference between the following two declarations in Java? (10)

i. int c [ ][ ], x ii. int [ ][ ] c, x

Write 2 (two) different ways of creating the following array in Java.

0 1 2 3 4 5 6 7 8 9

5(b). What are the problems with the following Java code? (10)

public class TestStatic { static int a = 3, b; int c; {

c = 10; } static {

b = a*4; c = b;

} int f2() {

return a*b; }

static void f1(int x) { System.out.println("x = " + x); System.out.println("a = " + a); System.out.println("b = " + b); System.out.println("c = " + c);

}

public static void main (String [] args) { f1(42); System.out.println("b = " + b); System.out.println("Area = " + f2());

} }

L-1/T-2/CSE Date: 17/01/2021

5(c). Consider the following code segment: (10)

public class Main { public static void main (String [] args) { int a = minmax ("min", 2, 1, 6, 4, 5); // a = 1 int b = minmax ("min", 3, 0, 6); // b = 0 int c = minmax ("max", 1, 2, 6, 5); // c = 6 int d = minmax ("max", 1, 3, 7); // d = 7

} }

Write the above minmax function in Java. You are allowed to write only one minmax function.

6(a). Consider the following code segment: (10)

interface i1 { default void f1() { } static void f2() { } void f3();

} interface i2 {

void f4(); void f5();

}

abstract class c1 implements i1 { abstract void f6(); final void f7() { }

} class c2 extends c1 implements i2 {

// your code }

Write minimum code in class c2 for successful

6(b). Suppose there are 8 methods defined as follows: (10)

void m1(), void m2(), void m3(), void m4(), void m5(), void m6(), void m7(), and void m8()

There are also 4 interfaces named as: interface x1, x2, x3 and x4.

There is also a class named MyClass that needs to be forced to implement all the above 8

methods, where you have to maintain the following constraints:

i. Each interface can define at most 2 methods. ii. The class MyClass can only implement 1 interface.

Write Java code for MyClass to achieve the above scenario.

L-1/T-2/CSE Date: 17/01/2021

6(c). Consider the following code segment: (10)

public class Institute { private int eiin; private int shift; private int version; private int group; public Institute (int eiin, int shift, int version, int group) { this.eiin = eiin; this.shift = shift; this.version = version; this.group = group; }

public static void main (String [] args) { Institute i1 = new Institute (135790, 1, 1, 0); Institute i2 = new Institute (135790, 1, 1, 0); System.out.println(i1.equals(i2)); HashMap map = new HashMap(); map.put (i1, 100); System.out.println(m.get(i2)); } } The expected output of the above code: true 100

Complete the Institute class to achieve the expected output.

7(a). With Java threads, it is very easy to parallelize computations. Suppose you are in a job interview and the interviewer asks any simple equation; you can only use loops. But you are asked to divide the work equally among 10 different threads. Write complete Java code to compute the summation of 1 to 10000000 by dividing the work equally among 10 different threads. The main thread will wait for the 10 threads to finish and will only print the final summation. (10)

7(b). Consider two entities, the Writer and the Reader, who share a common buffer that is a single

ead the

code to solve the above-mentioned problem using the concept of inter thread communication. You can use wait/notifyAll or ArrayBlockingQueue. (10)

7(c). Write three different ways to create Threads in Java with short code examples. What is the difference between synchronized method and synchronized statement? (10)

8(a). What do you mean by auto-boxing and auto-unboxing? Explain with code examples. When you Write three differences between Hashtable and HashMap? (10)

L-1/T-2/CSE Date: 17/01/2021

8(b). Write a generic interface named iQueue with methods enqueue, dequeue and isEmpty. Then write a generic class Queue that implements the iQueue interface. Please note that iQueue interface only supports numeric types. (10)

8(c). Consider the following class: (10)

class Product { private String name; private double price;

Product (String name, double price) {

this.name = name; this.price = price;

}

public String getName () { return this.name;

} public double getPrice () {

return this.price; }

}

Write Java code for the following:

i. Define an ArrayList named myProducts that can store a list of Product. ii. Generate 4 random Product with names 'A' to 'D' and random price and add them to

myProducts. iii.

techniques. You can change the Product class if necessary.