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 & Filtering

Given the following functions, What goes wrong when a main function makes a call to
displayRoot(5). Explain.
Make one change to the displayRoots() function to fix the problem and write the output.
#include <iostream>
using namespace std;
int k;
int funsqrt(int p)
{
k = 1;
while (k * k <= p)
{
k++;
}
return k-1;
}
void displayRoots(int p)
{
for (k = 0; k <= p; k++)
{
cout << funsqrt(k) << " ";
}
}
Assuming that a[] is an array of integer values, insert the missing statement in the
following code fragment, which is designed to replace each array element with its square.
for (int j = 0; j < LENGTH; j++)
{
____________________________
}
Read the following function and explain if this function finds the biggest value stored in
the array..
int biggest(int a[], int current_length)
{
int biggest = 0;
for (int i = 0; i < current_length; i++)
{
if (a[i] > biggest){
biggest = a[i];
}
}
return biggest;
}
Read the following function:
int findFirst(int a[], int current_length, int val)
{
bool found = false;
int pos;
for (pos = 0; pos < current_length && !found; pos++)
{
if (a[pos] > val){
found = true;
}
}
if (found)
return pos;
else
return -1;
}
Does the above function always find the correct position of the first occurrence of a given
integer value in an array, if the integer value exists in the array
Do the following 5 tasks. Each task is worth 2 points.
(a) Define an array of integers called primes containing the first five prime numbers.
(b) What are the contents of the array primes[5] after executing the following loop?
for (int k = 0; k < 2; k++)
{
primes[4-k] = primes[k];
}
(c) Consider the array primes[5] defined in part a. What is its contents after executing
the following loop?
for (int j = 0; j < 5; j++)
{
primes[j]++;
}
(d) Define an array containing two strings, ”Yes” and ”No”.
(e) Given the array you modified in part (c) print in reverse the elements of the array
prime

Consider an 8 x 8 array for a board game: int board[8][8]; Using two nested loops, initialize the board so that 0s, and 1s alternate as on a checker board.

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0

0 1 0 1 0 1 0 1

1 0 1 0 1 0 1 0


Write a function reverse that takes an array of strings as an argument and reverses it. The function does not return a value. Please do not create a new array. Modify the array parameter.

#include

#include

using namespace std;

void reverse_string(string s[], int size);

void print_array(const string s[], int size);

int main()

{

string words[] = {"Up", "above", "the", "world", "so", "high", "like", "a", "diamond", "in", "the", "sky"};

const int LENGTH = 12;

reverse_string(words, LENGTH);

print_array(words, LENGTH);

return 0;

Should print: sky the in diamond a like so world the above Up


Write a C Program that does the following:

1. Declares a C-String called ‘m1’ and initializes it with the text “Programming is great fun!”.

2. Uses C-function puts() to print this string.

3. Asks the user to enter a string named ‘m2’ (Hint: Use gets() function for this.)

4. Concatenates the two strings and stores the result in ‘m3’.

For example, if the user enters m2 as “Not Really!”, m3 should be “Programming is great fun! Not really!”

5. Inserts the user entered array (m2) into m1 after “Programming is ...”

For the above example, the resultant String would become “Programming is Not really! great fun!”


 Question Number 4 (CLO 3) (25 marks) Write an object oriented program that will ask the user to enter the specifications of a mobile phone so that the viewers can see them in advertisement form and can compare them for their best choice. Make the program in such a way that user can view the mobiles one by one or all the brands on the same screen. Some Useful Hints Create a class named smart_phone Put the mobile name, price, display size, memory, processor speed, camera and display resolution in private data. A member function will ask the user to enter the data for mobile • Another function will display the data of each object Another function will display the data by combining all the objects (this function will accept 3 objects as argument) and 4th object will be the object on which the function is called. • In main program declare 4 objects • Ask the owner to enter the details for 4 mobiles


Suppose that you are coding a cricket game. For this you need to take care of players, ground, crowd,

equipment (bat, ball, stumps etc) and Umpires. This task is too difficult with structural programming,

that why we need to go for Object Oriented Programming. Use the data modeling technique to find:

• Class(es)

• Object(s) in each class

• Attributes of each object

• Constant Object(s) of each class (if any)

• Method(s) of every class

• Static Data in all classes (if any)


LATEST TUTORIALS
APPROVED BY CLIENTS