Explore BrainMass
Share

C++ Square and Cube classes

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Derive the cube class from the base square class. Assume the square class has a protected member variable representing the side called side and declared as a double with a default value of 1.0. It also has a public function called calcVal that evaluates the area of a square as side * side.

In your derived class have the default values for side be 1. For the cube class include a public function calcVal that evaluates the volume of the cube. (Hint: The volume of the cube is side * square :: calcVal.)

© BrainMass Inc. brainmass.com October 25, 2018, 9:16 am ad1c9bdddf
https://brainmass.com/computer-science/cpp/c-square-and-cube-classes-569148

Solution Preview

Attached solution 569148.cpp creates a base class Square, and derives class Cube from it as per the given specifications. It also ...

Solution Summary

Solution creates a base class 'Square' with protected member 'side'. It then derives class 'Cube' from it that makes use of 'side' from parent class, and also overrides 'calcVal' method of the parent class.

$2.19
See Also This Related BrainMass Solution

C++ Code for Testing Random Number Generator

I am using "Numerical Recipes (3rd Edition)" to create a numerical method that computes random numbers. My problem is that I'd like to use tests such as Chi-Square to test the uniformity/performance of the generator, but I don't know how to do this.

You can see my basic number generator in the readable file randomnumbers. I've included portions from "Numerical Recipes" (which you can easily find on Scribd) on random numbers and statistical functions. Based on the structure of the codes, I need help writing a program that uses Chi-Square (or something else appropriate from statistical functions.pdf) to test my random number generator.

I am extremely new to c++, so if my bid is too low please let me know. I'm not sure how long the necessary code will be or how much expertise it will require, so I don't know how much you will charge.

In case you can't read my cpp code, it's very basic:

#include <iostream>
#include "/Users/.../Documents/NR/code/nr3.h"
#include "/Users/.../Documents/NR/code/ran.h"

int main(){
Int seed = 12345678;
Ran myran(seed);
for(int i=0;i<10;i++){
cout<<"Using ran = " << myran.doub() <<endl;
}
return 0;
}

and returns 10 random numbers. This is just an example, it probably isn't my final code, just something simple for you to see what I'm going for. Please note that I am very weak with c++ and really don't know much about what I'm doing.

View Full Posting Details