chap 13 part V

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

class Change { public: int pennies; int nickels; int dimes; int quarters; Change() { pennies = dimes = quarters = 0; } Change (int p , int n, d, q) { pennies = p; nickels = n; dimes = d; quarters = q; }

Both constructors are considered the default constructor.

#include <iostream> using namespace std; class Dumbell; { int weight; public: void setWeight(int); }; void setWeight(int w) { weight = w; } int main() { DumbBell bar; DumbBell (200); cout << "The weight is " << bar.weight << endl; return 0; }

The semicolon should not appear after the word DumbBell. The function header for setWeight should appear as: void DumbBell::setWeight(int w) The line that reads: DumbBell(200); should read: bar.setWeight(200); bar.weight cannot be accessed outside of the class because no access specifier appeared before it in the class, making the variable private to the class by default. This means the cout statement will not work.

#include <iostream> using namespace std; Class Moon; { Private; double earthWeight; double moonWeigth; Public; moonWeight (double ew); { earthWeight = ew; moonWeight earthWeigth / 6; } double getMoonWeigth(); { return moonWeight ; } } int main() { double earth ; cout >> "What is your weight? "; cin << earth; Moon lunar(earth); cout << "On the moon you would weigh" << lanar.getMoonWeight() << endl; return 0; }

The semicolon should not appear after the word Moon. The first character of the words private and public should not be capitalized. There should be a colon, not a semicolon, following the words private and public. Semicolons should not appear in the member function headers. In function main an argument is passed to a constructor that does not exist in the Moon class. The moonWeight member function should have been called prior to getMoonWeight.

class Circle: { private double centerX; double centerY; double radius; public setCenter (double, double); setredius (double); }

There should not be a colon after the word Circle. Colons should appear after the words private and public. A semicolon should appear after the closing brace.


Kaugnay na mga set ng pag-aaral

Chapter 11 - Urban Renewal and Community Development

View Set

Female Reproductive System Sherpath Questions

View Set

Intro to Computing - Chapter 2: Hardware

View Set

Introduction to Physiology Homeostasis Dynamic Study Module

View Set