C++ Answers

Questions answered by Experts: 9 913

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Harry loves numbers in the range [m1, m2] (m1 and m2 included). carry decides to gift harry an array of numbers for his birthday. harry wants to find the number of pairs of indices [l, r] for which the sum of all the elements in the range [l, r] lies between m1 and m2.


Come up with an algorithm with a worst case complexity of O(N2).

Now improvise this algorithm, assuming all numbers are positive integers.

What if the numbers could be negative as well? Can you think of an O(nlogn) solution in this case? (Hint: use sorting)


Write a C++ program to find the sum of integer and float array
elements using function overloading. Dynamic memory allocation
should be used for arrays.
Define a class to represent book with the following details.
Data Members:
Book-No, Book-name, author, publisher, price, No. of copies, No.
Of copies issued.
Member Functions:
a) Assign initial values
b) Issue a book after checking availability
c) Return a book
d) Display book information
Hint- use constructors, static class members
Create a class DATE to read the date and overload ++ (both prefix
and postfix) to generate the next date.
For Example, if d = 15/8/2019 output d++ or ++d should return
16/8/2019. Consider all possible test cases.
Create a class student with name, roll number, marks of 5 subjects
as data variables and use friend functions to read and display
student details.
Overload <, <= , > and > = operators to compare the total marks
scored by the student.
For example, if 40,60,50,50,100 are marks of students S1, and
100,100,100,100,100 are the marks of student S2 then S1 < S2, S1
<= S2 should return true and S1 > S2, S1 >= S2 should return false.
Faculty member at the university demonstrates a lackadaisical attitude toward work. They seldom go to class yet at the end of each month they receive full salary. Management has decided that GHs 200, 300, 400, and 500 will be deducted from a faculty’s salary if he/she offends once, twice, third time and forth time respectively in a month. This means that if a faculty member offends once in a month GHs 200 will be
deducted, if a faculty member offends twice in a month, GHs 500 (i.e. 200+300)
will be deducted, if a faculty member offends three times in a month GHs 900
(i.e. 200+300+400), will be deducted and if a faculty member offends four times in a month GHs 1,400 (i.e.
200+300+400+500). Assuming all faculty
members are on a flat salary rate of GHs 2500.

a. Write a program to request for the names of four faculty members and
number times he/she has absented him/herself from class. One of them
should have absented him/herself once, another twice, another three times
and another four times.
The Nobel peace prize. The process of selecting the winners for the various prices have been criticized as being biased especially from the side of the panel members. The committee of experts at a general council meeting decided to automate the selection process. On a trial bases, you have been engaged to develop a system that will automatically select a nominee as the winner of the award in two categories (peace and science). Your program should have the following functionalities.

a) Define a class named NobelAward. Your class must have two
functions, one of the functions should be named AwardCategory, and the
other function should be named AwardWinner. Your AwardCategory
must have a string argument and return the string when called. Your
AwardWinner function must contain two parameters, one should be a string called name and the other an integer called votes. When called (AwardWinner) it should return the name and highest votes as the winner for a particular category.

For this task you are asked to write a program that consists of a le recap.cpp and a

make le to compile and run it. You will need to include a blank data.txt le in your

submission as well. Your make fille must compile the executable as main. You are required to read this data, line by line, into a 2D dynamic array of strings.

The format of the line is as follows:

1,a,b,c,d

Each line starts with an ID, which is an int, and then will be followed by an unknown

number of strings separated by commas. Each string in the line is associated with the ID

of the line. Each line will have at least the ID and 1 item.

Once the items are stored in the array you need to print out the array in ascending order

based on the order IDs in the following format:

ID,a,b,c

An example of this output is as follows (for 2 orders):

3,toaster,iron

4,spanner,wrench,hammer

Terminate each line of output with a newline.

The following libraries are allowed:

- iostream

- fstream

- string

- sstream


Given the following declaration:
int j;
int sum;
float sale[10][7];
which of the following correctly finds the sum of the elements of the fifth row of sale?
1. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[5][j];
2. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[4][j];
3. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[5][j];
4. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[4][j];
Write a C++ program to check if 2 matrices are same b overloading == operator.
Two matrices A and B are said to be same if Aij = Bij for 0<=i,j<=n-1.
LATEST TUTORIALS
APPROVED BY CLIENTS