Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) Complete and test class String from 19.3. [3] ( 2) Define a class INT that behaves exactly like an int. Hint: Define INT::operator int().

2) Complete and test class String from 19.3. [3] ( 2) Define a class INT that behaves exactly like an int. Hint: Define INT::operator int(). [4] ( 1) Define a class RINT that behaves like an int except that the only operations allowed are + (unary and binary), (unary and binary), , /, and %. Hint: Do not define RINT::operator int(). [5] ( 3) Define a class LINT that behaves like a RINT, except that it has at least 64 bits of preci- sion. [6] ( 4) Define a class implementing arbitrary precision arithmetic. Test it by calculating the factorial of 1000. Hint: You will need to manage storage in a way similar to what was done for class String. Given a graph G = (V,E), a positive integer k, source s V and a target t V , is there a simple path from s to t of length at least k? Given a graph G = (V,E), a positive integer k, source s V and a target t V , is there a simple path from s to t of length at most k? One of these problems is known to be in P while the other one is known to be NP-complete. (a) Which of the two problems is in P and which is NP-complete? [2 marks] (b) Describe a polynomial time algorithm for the problem that is in P. [6 marks] (c) Give a proof of NP-completeness for the problem that is NP-complete. You may assume the NP-completeness of any problem, such as Hamiltonian Cycle, mentioned in the lecture course. [12 marks] [4] ( 2) Define a class Histogram that keeps count of numbers in some intervals specified as arguments to Histogram's constructor. Provide functions to print out the histogram. Handle out-of-range values.ddress the following Questions adhering to the requirements in each part.

Write program that receives three or more arbitrary numbers of integers until 0 is entered and calculates the average of the remaining numbers excluding the minimum and maximum values among the numbers excluding the last 0. However, use the scanf function only once throughout the program. Deduction for multiple use of scanf. Do not use arrays, use only conditional statements and loop statements. (Ex. 1 2 3 4 0 -> 2.5 / 1 2 3 4 6 0 -> 3)

Assume a simple movie database with the following schema. (You may assume that producers have a unique certication number, Cert, that is also recorded in the Movie relation as attribute prodC#; and no two movies are produced with the same title.) Movie(title,year,length,prodC#) StarsIn(movieTitle,movieYear,starName) Producer(name,address,cert) MovieStar(name,gender,birthdate) (a) Write the following queries in SQL: (i) Who were the male stars in the lm The Red Squirrel? [1 mark] (ii) Which movies are longer than Titanic? [2 marks] (b) SQL has a boolean-valued operator IN such that the expression s IN R is true when s is contained in the relation R (assume for simplicity that R is a single attribute relation and hence s is a simple atomic value). Consider the following nested SQL query that uses the IN operator: SELECT name FROM Producer WHERE cert IN (SELECT prodC# FROM Movie WHERE title IN (SELECT movieTitle FROM StarsIn WHERE starName='Nancho Novo')); [7] ( 2) Write a program that has been rendered unreadable through use of operator overloading and macros. An idea: Define + to mean and vice versa for INTs. Then, use a macro to define int to mean INT. Redefine popular functions using reference type arguments. Writing a few misleading comments can also create great confusion. [8] ( 3) Swap the result of X.19[7] with a friend. Without running it, figure out what your friend's program does. When you have completed this exercise, you'll know what to avoid C

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

2 What a price index is and how it is calculated

Answered: 1 week ago