Show the output of the following code:
Want to see the full answer?
Check out a sample textbook solutionChapter 1 Solutions
Introduction to Programming with C++
- 1. C++: Complete the following incomplete code to a executable C++ program): [4C Open with Google Docs class Array{ int* dataPtr; int noofElements; float avg; public: // define necessary getter and setter method (s) // define other necessary method (s) to support the main () //NO friend is ALLOWED }; class ArrayOfArrays { Array* ptrToArrays; int noofArrays; public: // define method: "setArrayofArrays" // set random integers and calculate avg to the fields for // each of ptrToArrays [i] [see RUN] // define method: "showArrayofArrays" // show elements and avg as per the RUN // define method: "getAvgofAvgs" // display the average of array-averages as per the RUN //NO friend is ALLOWED }; int main ()) { ArrayofArrays obj; int n = rand () 810, max = 100; // n = no of Array to be pointed by ptrToArrays in obj, i.e. noofArrays // max is the upper limit of random values for Array elements in dataPtr obj.setArrayOfArrays (n, max).showArrayofArrays () ; // Explanation of setArrayofArrays (n,…arrow_forward#include<stdio.h> #include<stdarg.h> void fun1(int num, ...); void fun2(int num, ...); int main() { fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0; } void fun1(int num, ...) { char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str); } void fun2(int num, ...) { va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num); }.arrow_forwardThis assignment is not graded, I just need to understand how to do it. Please help, thank you! Language: C++ Given: Main.cpp #include #include "Shape.h" using namespace std; void main() { /////// Untouchable Block #1 ////////// Shape* shape; /////// End of Untouchable Block #1 ////////// /////// Untouchable Block #2 ////////// if (shape == nullptr) { cout << "What shape is this?! Good bye!"; return; } cout << "The perimeter of your " << shape->getShapeName() << ": " << shape->getPerimeter() << endl; cout << "The area of your " << shape->getShapeName() << ": " << shape->getArea() << endl; /////// End of Untouchable Block #2 //////////} Shape.cpp string Shape::getShapeName() { switch (mShapeType) { case ShapeType::CIRCLE: return "circle"; case ShapeType::SQUARE: return "square"; case ShapeType::RECTANGLE: return "rectangle"; case…arrow_forward
- #include using namespace std; (а) class Fraction{ int x, y; public: Fraction (int a, int b) {x=a; y=b;}; int getx(){return x;} int gety() {return y;} } ; int main() Fraction n(3, 7); ++n; cout << "x/y: " <« n.getx()<< "/" « n.gety()<arrow_forwardint j; for (int i = 0; i < 5; i++) {j = 2*j*i;} What is j?arrow_forwardoop using c++ please give me full answer thanks Write a Program that implements Base class calculator and a Derived class scientific calculator, The Derived class should take the basic operations i.e. add, divide, subtract from calculator. However it should have its own methods such as square root.arrow_forward#include void main(void) { int c =2 ^3; cout<< c; }arrow_forwardFOR C++, PLASE SEND THE ANSER IN 30 MINUTES. ACCORDING TO CODE BELOW, #include "Vehicle.hh" class Ship: public Vehicle { private: int passenger; public: Ship(); Ship(int, float, float); int getPassenger(); void setPassenger(int); void print(); }; (DEFINE FUNCTIONS CORRESPONDING TO SHIP HEADER CLASS IN PART 2 BELOW) #include "Vehicle.hh" #include "Ship.hh" #include <iostream> using namespace std; // *** DEFINE --VEHICLE-- FUNCTIONS FOR PART 1 *** // *** DEFINE --SHIP-- FUNCTIONS FOR PART 2 *** void reduceSpeed(Ship*, float); void takePassenger(Ship*, int); int main() { return 0; } // reduce the speed of ship given in percentage (0 < percentage < 1). void reduceSpeed(Ship *s, float percentage) { // *** FILL THIS FUNCTION FOR PART 3 *** } // takes the number of passengers to the ship void takePassenger(Ship *s, int pas) { // *** FILL THIS FUNCTION FOR PART 4 *** }arrow_forwardc++ Friend function concepts Do not use operator overloading Write a Program to design a class complex to represent complex numbers and an input method "void input(float X, float Y)" for setting the values of complex number. Class should use an external friend function "friend complex sum (complex, complex);" to add two complex numbers and should return an object of type complex representing the sum of two complex numbers. Write another method "void show (complex c)" to show the final summation.arrow_forwardCourse: Object Oriented programming Lnaguage: C++ You have to solve the Make the program correctly and in 2 hours. kindly Make program correct as much as you can. Question: Develop a polymorphic banking program using the Account hierarchy in which two types of Accounts can be created i.e.Current Account and Saving Account respectively. Each account must have to give the interest to the bank depending upon their account type. A function of name InterestRate() will calculate the interest of account and returns the interest amount. Current Account has annual interest rate of 0.1% of actual amount and SavingAccount will have to pay interest rate of 1.0% of actual amount. Also write a main function for polymorphic calls of the functions. Note: Polymorphic calls for the functions are necessary. Necessary constructor, Destructors, setters, getters and other functions should also be defined.arrow_forwardExercise 10 Automatic type conversion is called coercion. For example, if an int variable and a float variable are added in Java, the value of the int variable is coerced to float and a floating-point add is done. True or Falsearrow_forwardc++arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT