C++ help with an assignment

Im fairly new to c++ and need help with my assignment in school. Can anyone please show me how to program this?

Write a C++ program that models an airplane.

1) Write a class that represents the airplane itself. It should have make, model, and another variable of your choice. Make sure these variables are private.
2) Write getters and setters for all of these variables. Remember that a getter is just a function that returns the value of a data member, and a setter is a function that takes a parameter and stores that value in the data member.
3) Write a class that represents an airplane engine. It should have private data members for rpm, make and model (make and model of the engine are not the same as for the airplane), and one additional variable of your choice.
4) Write getters and setters for these variables as well.
5) The airplane class should have 2 data members that are instances of the engine class.
Write a function in the airplane class that will print out all of the airplane’s information, including printing out the information for the engines. Have main create an airplane and cause it to print its information.
Please post your code, with code tags - the <> button on the right. Also post your compiler output in full please - it makes it easier for us.
well i havent exactly gotten very far. Im basically stuck towards the beginning. Ill post what I have, give me a few. Im using visual studio 2010 c++. Ill post my code and all here in a few.
heres all I have at the moment.

plane.h

#include <string>
#include <iostream>
#ifndef plane_H
#define plane_H
using namespace std;

class plane{

private:

string make;//private variable for make of plane
string model;//private variable for model of plane
string color;//private variable for color of plane

public:

void planeMake();//getter for make
void setplaneMake(string);//setter for make
void planeModel();//getter for model
void setplaneModel(string);//setter for model
void planeColor();//getter for color
void setplaneColor(string);};//setter for color

plane.cpp

#include "plane.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void main(){

engine.h

#include <string>
#include <iostream>
#ifndef engine_H
#define engine_H
using namespace std;

class engine{

private:

string rpm;//private variable for rpm of engine
string make;//private variable for make of engine
string model;//private variable for model of engine
string size;//private variable for size of engine

public:

void engineRpm();//getter for rpm
void setengineRpm(string);//setter for rpm
void engineMake();//getter for make
void setengineMake(string);//setter for make
void engine model();//getter for model
void set engineModel(string);//setter for model
void engineSize;//getter for size
void setengineSize(string);};//setter for size

engine.cpp

#include "engine.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void main(){
Last edited on
void int main(){ main returns an int. Always and forever.

Anyway, you need to write the getter and setter functions. They're very simple. All they do is change the value of something in the class, or return the value of something in the class. I note that all your getter functions don't currently return anything. That needs to change.
Last edited on
If anyone writes this it would definately help me out. see if you can do the assignment bc I know I cant.
Well then time to suck it up and fail the assignment. Perhaps your teacher will note that you're unable to do this and direct you back towards the basics of functions.
i figured it out with a little help, not as hard as I thought, I just wanted to see how someone would do the assignment thats not from my college and see what their background is like and how it compares to what we're being taught. One thing though is our teacher showed us many examples and wants us to use void on everything like I showed, and not int. Not sure why.
You would use void for the setter function. Not for the getter. There the type will be the same as the type of whatever it is you are getting.
If you take notice of what I said in bold earlier, then I might be prepared to help. Others too.

Am looking forward to helping.

One thing though is our teacher showed us many examples and wants us to use void on everything like I showed, and not int. Not sure why.


Well you have misunderstood your teacher, as Moshops has said a get function must return something.
Topic archived. No new replies allowed.