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

Task 1:
Complete the body of this function. You do not need to check the precondition. You
may use the stack template class
bool balanced(const char p[ ], size_t n)
// Precondition: p[0]...p[n-1] contains n characters, each of which
// is '(', ')', '{' or '}'.
// Postcondition: The function returns true if the characters form a
// sequence of correctly balanced parentheses with each '(' matching
// a ')' and each '{' matching a '}'. Note that a sequence such as
// ( { ) } is NOT balanced because when we draw lines to match the
// parentheses to their partners, the lines cross each other. On the
// other hand, ( { } ) and { ( ) } are both balanced.
Task2:
Consider following Linked List:
struct Node {
int data;
Node *next;
class LList {
public:
LList();
~LList();
private:
Node *head;
int size;
};
LList::LList () {
head = NULL;
size = 0;
}
Implement the destructor LList::~LList ().
Note: You can use same linked list used in Task 1 and Task 2.
Write code that performs all operations on doubly Linked List
Note:
1)use class or struct
2)no global declarations

Create a class student which stores name, roll number and age of a student. Derive a

class test from student class, which stores marks in 5 subjects. Input and display the

details of a student.Extend this program to include a class sports, which stores the marks in sports activity.

Derive the result class from the classes ‘test’ and ‘sports’. Calculate the total marks and

percentage of a student.


Create a class student which stores name, roll number and age of a student. Derive a

class test from student class, which stores marks in 5 subjects. Input and display the

details of a student.Extend this program to derive a class from result from class ‘test’ which includes

member function to calculate total marks and percentage of a student. Input the data for a

student and display its total marks and percentage.


The following program is supposed to allocate nodes, put them into a linked list, print them out and then destroy them. Fix the bugs in the program and rewrite the code. Your program should have complete implementation required to run the following function. Take dummy data execute it, take snap shot and paste it in the document. struct linkedList{ int number; linkedList* next; }; void AddNode() { linkedList* head=NULL; linkedList* current; for(int i=0;i<10;i++){ current = new linkedList; current->number = i; current.next = head; head = current; } while(head->next!=NULL){ cout << head->number << endl; current = head->next; delete current; head = current; } return 0; }


Describe the problem analysis-coding-execution cycle.
A) Write a program to confirm if a given number is a prime number or not.

B) Illustrate the above with a flowchart.

R=v2 sin2&/g

v = 30.0 (speed of the throwing), g = 9.8 (gravity), and $= angle in radians





User may insert an angle above or equal 45° and below 60° as the highest angle.

Then the program should calculate the horizontal range of the projectile motion (R) for each angle until the angle become 35°.

Consider the gravity (g) as a constant.

You are required to calculate the 𝜃 in radians by using the given formula (PI = 3.14286 which is a constant).

Use the necessary header files to do the calculation.


Write a C++ program to calculate the period of a conical pendulum (T) when a stone of mass 1 kg is whirled in a horizontal circle attached at the end of a 1.75 m long string and making an angle (in degrees) with the vertical is given by the user. The given below is the equation to calculate the period of a conical pendulum.

I cos 0

9

T

= 2n

1 = 1.75 m (length of the pendulum), g = 9.8 (acceleration due to gravity), and 8= half-angle of the conical

pendulum

• User may insert an angle above or equal to 30 and below 45" as the highest angle. • Then the program should calculate the period of a conical pendulum (1) for each angle until the angle

becomes 20".

. Consider gravity (g) as a constant. You are required to calculate the in radians by using the given formula (Pl = 3.14286 which is a constant).

Theta Ang/180.0 PI

• Use the necessary header files to do the calculation

Sample Output

Enter

35

34

33

32

Angle in Degrees: 35

2.40384 2.41832

2.43234

2.44591

Write a C++ program to calculate time dilation (t) in motion, when the speed of the moving objects (v) is given by the user. The given below is the equation to calculate the time dilation.




v = speed of the moving object, c = 15000 ms-1(speed of light), and t0 = 75 s (time in observers own frame of reference)

  • User may insert the speed of the moving objects (v) above or equal to 100 ms-1 and below 200 ms-1 as the highest speed.
  • Consider the speed of light (c) as a constant value.
  • Then the program should calculate the time dilation (t) for each speed of the moving object until the speed becomes 89 ms-1.
  • Use the necessary header files to do the calculation.
LATEST TUTORIALS
APPROVED BY CLIENTS