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

//One line of code to calculate the acceleration of a object


Write a program that prompts the user to input height and width and print the hollow rectangle

as given in the output below. The program should check whether the both height and width

of rectangle are equal or not. Do not use nested loops.


In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle.


Determine whether the following are valid switch statements. If not,


explain why. Assume that n and digit are int variables. (11)



a. switch (n <5 2)


{


case 0:


cout << "Draw." << endl;


break;


case 1:


cout << "Win." << endl;


break;


case 2:


cout << "Lose." << endl;


break;


}






b. switch (digit / 4)


{


case 0,


case 1:


cout << "low." << endl;


break;


case 1,


case 2:


cout << "middle." << endl;


break;


case 3:


cout << "high." << endl;


}






c. switch (n % 6)


{


case 1:


case 2:


case 3:


case 4:


case 5:


cout << n;


break;


case 0:


cout << endl;


break;


}





d. switch (n % 10)


case 2:


{


case 4:


case 6:


case 8:


cout << "Even";


break;


case 1:


case 3:


case 5:


case 7:


cout << "Odd";


break;


}


Suppose that sale and bonus are double variables. Write an if...else


statement that assigns a value to bonus as follows: If sale is greater


than $20,000, the value assigned to bonus is 0.10, that is 10%; If sale


is greater than $10,000 and less than or equal to $20,000, the value


assigned to bonus is 0.05, that is 5%; otherwise the value assigned to


bonus is 0, that is 0%.


What is the output of the following C11 code? (2, 5, 6)


int x = 15;


int y = 3;


if (x + y > 17 || y - x < 20)


{


y = x - y;


x = y + x;


cout << x << " " << y << " " << x + y << " " << y - x << endl;


}


else


{


x = y - x + y %5;


cout << x << " " << y << " " << x - y << " " << x + y << endl;


}


What is the output of the following program?


#include <iostream>


using namespace std;



int main()


{


int firstNum = 28;


int secondNum = 25;


cout << firstNum << " " << secondNum << endl;


cout << (firstNum = 38 - 7) << endl;


cout << (firstNum <= 75) << endl;


cout << (firstNum > secondNum + 10) << endl;


cout << (firstNum >= 3 * secondNum - 100) << endl;


cout << (secondNum - 1 == 2 * firstNum) << endl;


cout << firstNum << " " << secondNum << endl;


return 0;


}

Consider the myString class, which is having only one privately declared data item: string str; OR char str[MAX]; and publically declared constructors and required member functions. Write down a member function that subtracts one object’s string from another object’s string. Sample calling statements are given as under. myString S1, S2, S3; S1.readd(); S2.readd(); S3 = S1 – S2;


1) Create a class phoneUser. The class should have the following private data members. The class prototype should be stored in the header file phoneUser.h

• Name of phone user (string type)

• Surname of phone user (string type)

• Number of phone user (string type)


Write public getters and setters to modify these data members. Write the function implementation in the source file phoneUser.cpp. There should be three constructors, with no argument (default constructor), with 2 arguments (Name and Surname), with three arguments (Name, Surname, and Number).




Implement a Stack to store a character in the node. Implement the following operations

push, pop and peek:.

void push (char c);

char pop();

char peek();

int isEmpty();

void printStack();



LATEST TUTORIALS
APPROVED BY CLIENTS