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

Print a message telling a user to press the letterToQuit key numPresses times to quit. End with newline.

•Ex: If letterToQuit = 'q' and numPresses = 2, print:

#include <iostream>

using namespace std;

int main() {

  char letterToQuit;

  int numPresses;

  cin >> letterToQuit;

  cin >> numPresses;

  /* Your solution goes here */

  return 0;

}

Create a class called myMath. This class only contains one basic data type (float x). Your class should mimic the +,-,*,/ function in a basic data type. In other words, you need to provide the basic math operations for the objects created under myMath.


main()

{

  myMath m1(10),m2(2),m3; //you can change 10 and 2 to any value to test your code.

m3 = m1 + m2;

  cout <<"\nAddition: "<< m3.getX(); //output is 12

  m3 = m1 - m2;

  cout <<"\nSubtraction: "<< m3.getX(); //output is 8

  m3 = m1 * m2;

  cout <<"\nMultiplication: "<< m3.getX(); //output is 20

  m3 = m1 / m2;

  cout <<"\nDivision: "<< m3.getX(); //output is 5

}


Define a class Pairs with two integer data members, f and s, where f represents

the first value in the ordered pair and s represents the second value in an ordered

pair. Write a program to test all the overloaded operators in your class definition.


Overload the stream extraction operator >> and the stream insertion operator << as

friend functions so that objects of class Pairs are to be input and output in the

form (5,6) (5,-4) (-5,4) or (-5,-6).


Overload binary operator + as a friend function to add pairs according to the rule

(a,b) + (c,d) = (a + c, b + d)


Overload operator – as a friend function in the same way, i.e. according to the rule

(a,b) - (c,d) = (a - c, b - d)


Overload operator * as a friend function on Pairs and int according to the rule

(a,b) * c = (a * c, b * c)

Overload the +, - and * operators for objects of class Pairs, as member functions. Also, define the class Pairs as an ADT that uses separate files for the interface and the implementation.


An odometer is an instrument used for measuring the distance travelled by a vehicle. Define a class called Odometer that can be used to track fuel and traveling distance for a car. Include private member variables to track the distance driven and the fuel efficiency of the car in kilometres per litre. The class should have a constructor that initializes these values to 0. Include a default constructor to initialize both member variables to zero, a member function to reset the odometer to zero km, a member function to set the fuel efficiency, a member function that accepts km driven for a trip and adds it to the odometer’s total, a member function that returns the number of L of fuel that the car used since the odometer was last reset, and a destructor. Use your class with a test program that creates odometers for different cars with different fuel efficiencies. Let the cars do several trips. Reset the odometers at the start. Display the distance and the litres of fuel consumed after each trip. 


create a class Matrix the stores it in a safe 2D array .that is it it should check for array index bounds .a constructor should allow the programmer to specify the actual dimensions of the matrix. define number functions : putel() for taking 3 argument row index , column index and the element storing it in the corresponding location. getel() for taking 2 arguments row and column indexes and returns the elements from that location . overload the operators +,-,and * appropriately


Write a program to writing in to a text file, read from a text file and display in c++


write a program for conversion from decimal to binary ,octal and hexadecimal .the program should be developed as follows:


(a).the base class convert has two variables initial and result in which initial is a number before conversion and result is 

after conversion.


(b). it has two member functions getinit() and getconv() which return the initial value and converted value respectively.


(c). write a function compute which is a pure virtual function that actually does the conversion.


(d). separate derived classes for hexadecimal ,binary, octal, does the conversion by implementing the function compute.


(e). create the objects for each class using new operator.


(f). use the convert class type pointer to call the compute functions of the derived classes.


write a program to copy content of one file to another file in c++


Create a person class with name as data member provide four functions in getname() to get input from user and put name to display output write two virtual functions getdata() and outstanding() where both these functions takes no argument and getdata() returns no value but outstanding() returns Boolean value . Derive student and professor from person. student class should contain gpa as its float type and overrides the virtual functions appropriately . In professor class provide number of applications as data members and override the virtual functions appropriately . Write a main program to declare a array of pointers to person object and depending on the choice from user create either a student object or professor object and store it in person array for n persons and display the details along with whether the person is outstanding or not



Write a program to create a numeric file and split the file into two files, one containing all odd

numbers and another with even numbers.



LATEST TUTORIALS
APPROVED BY CLIENTS