Saturday 9 July 2016

Create a class called shipthat incorporates a ship’s number and location. Use the
approach of Exercise 8 to number each shipobject as it is created. Use two variables of
theangleclass from Exercise 7 to represent the ship’s latitude and longitude. A member
function of the shipclass should get a position from the user and store it in the object;
another should report the serial number and position. Write a main()program that creates three ships, asks the user to input the position of each, and then displays each ship’s
number and position...


#include<iostream>
#include<conio.h>

using namespace std;

class ship{
private:
int serial;
static int num;
int degrees;
float minutes;
char direction;
public:
ship(){
num++;
serial = num;
}
void getLoc(){
cout << "Enter Degrees: "; cin >> degrees;
cout << "Enter Minutes: "; cin >> minutes;
cout << "Enter Direction: "; cin >> direction;
}
void reportSerLoc(){
cout << "Ship Number " << serial << " Is At " << degrees << '\xF8' << minutes << "\'" << direction << endl;
}
};
int ship::num=0;

int main(){
ship s1,s2,s3;
cout << "Enter Location Of 1st Ship" << endl;
s1.getLoc();
cout << "Enter Location Of 2nd Ship" << endl;
s2.getLoc();
cout << "Enter Location Of 3rd Ship" << endl;
s3.getLoc();
s1.reportSerLoc();
s2.reportSerLoc();
s3.reportSerLoc();
}

1 comment: