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

errors executing this code

|18|error: expected initializer before 'Myclass'|

|22|error: expected declaration before '}' token|


#include<iostream>

using namespace std;

class Myclass {

  private: 

    int u=10;

    int v=20;

    int w=30;

    int x=40;

    int y=50;    

  public:

    Myclass() : x(10), y(x + 10) {}

    void print();

};

void Myclass::print()

{

cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y; 

}

int add Myclass::display()

{

  return x+y;  

}

}

int main()

{

    Myclass objone;

    objone.print();

    objone.display();

    getchar();

    return 0;    

}


create a calculator using C++ (OOP) with all operations and contain round and square parentheses and it supports the following operations: addition, subtraction, multiplication, division, power, nth root use a minimum of 4 classes, should contain at for invalid expressions the calculator will display an error message - All the attributes will have getters and setters; the setters will contain validations. Each class will have at least two operators overloaded from the following ones (the same operator will not be overloaded for two different classes):

  • index operator []
  • an implicit or explicit cast
  • a conditional operator (<.>,=<,>=,==)

For examples of inputs:

1- [4+(5-1)]*2 should output 16

2- 5 / 0 will display an error because division to 0 does not make sense


The calculator will take the input from the console. The user will have the ability to write equations and entering the app will display the result.

Take input for the radius of a circle then calculate its area, circumference and diameter,



hen output the three results.



(Area= nr²



circumference=2ftr



diameter=2r)

Create a class called Rational for performing arithmetic with fractions. Write a driver program to test your class.

Use integer variables to represent the private data of the class—the numerator and the denominator. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form

Provide public member functions for each of the

following:

a) Addition of two Rational numbers. The result should be stored in reduced form.

b) Subtraction of two Rational numbers. The result should be stored in reduced form.

c) Multiplication of two Rational numbers. The result should be stored in reduced form.

d) Division of two Rational numbers. The result should be stored in reduced form.

e) Printing Rational numbers in the form a/b where a is the numerator and b is the denominator.





Write the following program in c++.

Combine your first and second name and pick only the first five characters of your name for the project.

i. Declare an array named name1 and put all the first five characters into it.

ii. Write a for loop with an if condition that will find and output the index value of a

searched character in the array. Let the program be such that the user will input the character being searched for.


Question 2 (15 marks) 300-500 words per discussion and avoid plagiarism. Discuss the following.

a. b. c. d. e.

Pointers Arrays Structures

Classes functions


ii. Write a program in C++ with the following datatypes. Use the 3 different variables with the same data type. Explain the codes step by step.

a. int

b. float.

c. double. d. string. e. bool.


Question 1 (30 marks) 100-500 words per explanation and avoid plagiarism.

i. Explain the following datatypes in your own words without copying it from

anywhere.

a. int

b. float.

c. double. d. string. e. Bool.


Then write a cpp program that outputs get mortality rate etc . derive a class hierarchy for the item set given below

Item sets 


Virus , CovidVirus , HivVirus , BirdFlue etc | Virtual Function int GetMortalityRate();



The program below computes the grade of five students based on the marks scored. Study it carefully, identify the different errors the program has, correct the errors and hence re-write the program so that it can run successfully without errors.



LATEST TUTORIALS
APPROVED BY CLIENTS