Questions: 9 913

Answers by our 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 & Filtering

#include <iostream> using namespace std; #include <string>



class cat



string color="White": string action="sitting"



Your Code Here



int main()



cat cl;



cat c2("Black"):



cat c3("Brown", "jumping");



cat c4("Red", "purring");



cl.print_cat():



c2.print_cat();



c3.print_cat():



c4.print_cat():



cl.change_color("Blue"); c3.change_color("Purple");



cl.print cat();



c3.print_cat():



return 0:



Complete the cat class so the main function above produces the following output:



White cat is sitting



Black cat is sitting Brown cat is jumping



Red cat is purring



Blue cat is sitting Purple cat is jumping

Complete the cat class so the main function above produces the following output:




White cat is sitting




Black cat is sitting Brown cat is jumping




Red cat is purring




Blue cat is sitting Purple cat is jumping

1. Write a program that will illustrate the use of a function for computing the square of a number. There must be three other functions aside from main(). The First function must be responsible for inputting the data, the second for computation of squares and the third, for Displaying the result. 10 points


Creat a program with the compilation of your activities in prelim

Implement your own string class using only primitive data types. Your string class should contain some of the same functionality as the string class in C++.

Your class should have the following member variables:

1. char *data

2. int length

Your object should have the following constructors and destructor:

1. String(): default constructor

2. String(int size)

3. String(char* str)

Note: You can assume that any character array that is sent as str will be terminated

by a null character (‘\0’)

4. String(const String &str)

5. ~String()

Your class should have the following functions:

1. int strLength()

2. void clear()

3. bool empty()

4. int charAt(char c)

5. char* getdata()

6. bool equals(char*str)

7. bool equalsIgnoreCase(char* str)

8. char* substring(char* substr, int startIndex)

9. char* substring(char* substr, int startIndex, int endIndex)

10. void print()


Implement a class Sequence to store a sequence of non-negative integer values, and the length

of the sequence. The class has the following private data members:

1. int length – the length of the sequence

2. int *pseq – a pointer to a dynamic integer array holding sequence of integers

The class shall provide the following public methods:

1. Sequence() – a default constructor that initializes length to 10 and store the sequence of

all zeros in an array.

2. Sequence(int lengthVal, int n1=0,int n2=0,int n3=0, int n4=0, int n5=0, int n6=0, int n7=0,

int n8=0, int n9=0, int n10=0) – another parameterized constructor should initialize the

length and array to sequence values passed in the arguments.

3. Sequence(Sequence &s) – a copy constructor that creates a copy of a Sequence object.

4. int getLength() – a getter for length

5. int* getSeq() – a getter for the sequence of numbers

6. void Sort(int n) – a function that sorts the first n elements in the sequence array. You

cannot use Bubble Sort Algorithm


Implement a class Matrix to create matrices of 2x2, 3x3 and 4x4 with the following private data members:

1. int **matrix – a double pointer of type integer to create a 2D array (matrix)

2. int row – an integer to store the rows in the matrix

3. int col – an integer to store the columns in the matrix

The class shall have the following public member functions:

1. Matrix (int n1, int n2, int n3, int n4, int row = 2, int col = 2) – a parametrized

constructor for a 2x2 matrix

2. Matrix (int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int row = 3,

int col = 3) – a parametrized constructor for a 3x3 matrix

3. Matrix (int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10, int

n11, int n12, int n13, int n14, int n15, int n16, int row = 4, int col = 4) – a

parametrized constructor for a 4x4 matrix

4. Matrix(const Matrix &m) – a copy constructor

5. ~Matrix() – a destructor

6. int getRow() – a getter for rows

7. int getCol() – a getter for columns



Implement a structure, Car. The structure has the following data member:

1. int petrolLevel – that indicates the liters of petrol in the car’s petrol tank. PetrolLevel for

this car can only be in the range 0 – 45 liters.

The structure has the following member functions:

1. void setPetrolLevel(int petrolLevelVal) – a setter for petrol level, cannot set value greater

than 45.

2. int getPetrolLevel() – a getter for petrolLevel

3. Car() – a default constructor

4. Car(int petrolLevelVal) – a parametrized constructor

5. bool MoveCar(int distanceKM) – a function that takes an integer as an argument and

moves the car to the argument value which is in Km. Provided the petrol tank has enough

fuel. Successful movement of the car returns true otherwise returns false. Moving for

each km causes the petrolLevel to go low by one.

6. void Refill() – a function that refills the car tank to the maximum value of petrolLevel

7. bool isEmpty() – a function that tells whether the Petrol tank is Empty or not


Write a recursive function that returns number of occurrences of a certain letter in a given string.








Let the function prototype be int countLetter(char letter, string str). For example, if








letter = "l" and str = "lollipop", the function should return 3.

You've learned in the past lessons on how to use square root functions, right? Then let's take your knowledge to the test. Print out the square root of a given integer with only two decimal places.






Ready, solve, and go!






Input






A line containing an integer.






4






Output






A line containing a decimal with two decimal places.






2.00

LATEST TUTORIALS
APPROVED BY CLIENTS