Explore BrainMass
Share

Guidance using classes in C++

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

I am trying to learn about how to use classes with private and public variables in c++. I've got a conversion program that I would like to use as a prop.

If I was to add a class to this program, what I think I know is...

(Just to say, this is still fresh and I don't have a full grasp of all the concepts yet)

I know that to start a class, you must first declare it like for example...

class Conversion
{
private:
int inches;
int foot;

public:
void conversion(int happen);
};

© BrainMass Inc. brainmass.com March 21, 2019, 6:05 pm ad1c9bdddf
https://brainmass.com/computer-science/cpp/guidance-using-classes-in-c-244228

Attachments

Solution Preview

The attached code is in C++ and uses C++ class to convert foot and inches to Centimeters. It modifies the given program to accomplish this.

// 244228-classExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>

using namespace std;

class Conversion
{
// VARIABLE DECLARATIONS:
private:
float inches; // number of inches
float foot; //number of feet
float centimeters; // number of centimeters

public:
Conversion(){
inches = 0;
foot = 0;
centimeters = 0;
}
void convert();
float getInches();
void setInches(float in);
float getFoot();
void setFoot(float ft);
float getCentimeters();
void showOutput();
};

float Conversion::getInches(){
return inches;
}

void Conversion::setInches(float in){
inches = ...

Solution Summary

This solution provides guidance for uses classes in C++.

$2.19