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();
}

ADD Any Two Number.......... 

#include <iostream>
#include <conio.h>
using namespace std;
class Int{
private:
int intvar;
public:
Int(){
intvar = 0;
}
Int(int x){
intvar = x;
}
void display(){
cout << intvar << endl;
}
void add(Int x, Int y){
intvar = x.intvar + y.intvar;
}
};
int main(){
Int a(5),b(45);
Int c;
c.add(a,b);
c.display();
}

Repeat Again any Sentence/Paraghraph........ 

#include <iostream>
#include <conio.h>
using namespace std;
class count{
private:
int serial;
static int num;
public:
count(){
num++;
serial=num;
}
void reportSerial(){
cout<<"I'm Object Number "<< serial << endl;
}
};
int count::num=0;
int main(){
count f1,f2,f3;
f1.reportSerial();
f2.reportSerial();
f3.reportSerial();
}

Thursday, 7 July 2016

Transform the fraction structure from Exercise 8 in Chapter 4 into a fraction class. Member data is the fraction’s numerator and denominator. Member functions should accept input from the user in the form 3/5, and output the fraction’s value in the same format. Another member function should add two fraction values. 

Write a main() program that allows the user to repeatedly input two fractions and then displays their sum. After each operation, ask whether the user wants to continue....


#include<iostream>
#include<conio.h>
using namespace std;

class fraction{
private:
int numerator, denominator;
char c;
void dispFct()
{
cout<<numerator<<"/"<<denominator;
}
public:
void getFct(){
cout<<"Enter fraction: "; cin>>numerator>>c>>denominator;
}
void addFct(fraction x, fraction y){
numerator=x.numerator*y.denominator+x.denominator*y.numerator;
denominator=x.denominator*y.denominator;
+cout<<"Sum = "; dispFct();
}
};

int main()
{
fraction f1,f2,f3;

f1.getFct();
f2.getFct();
f3.addFct(f1, f2);
}

Create a class that includes a data member that holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this,you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. 

What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each one about its serial number. They should respond I am object number 2,and so on.


#include <iostream>
#include <conio.h>
using namespace std;
class count{
private:
int serial;
static int num;
public:
count(){
num++;
serial=num;
}
void reportSerial(){
cout<<"I'm Object Number "<< serial << endl;
}
};
int count::num=0;

int main(){
count f1,f2,f3;
f1.reportSerial();
f2.reportSerial();
f3.reportSerial();
}

In ocean navigation, locations are measured in degrees and minutes of latitude and longitude. Thus if you’re lying off the mouth of Papeete Harbor in Tahiti, your location is 149 degrees 34.8 minutes west longitude, and 17 degrees 31.5 minutes south latitude. This is

written as 149°34.8’ W, 17°31.5’ S. There are 60 minutes in a degree. (An older system also divided a minute into 60 seconds, but the modern approach is to use decimal minutes instead.) Longitude is measured from 0 to 180 degrees, east or west from Greenwich, England, to the international dateline in the Pacific. Latitude is measured from 0 to 90 degrees, north or south from the equator to the poles. 
Create a class angle that includes three member variables: an int for degrees, a float for minutes, and a char for the direction letter (N, S, E, or W). This class can hold either a latitude variable or a longitude variable. Write one member function to obtain an angle value (in degrees and minutes) and a direction from the user,and a second to display the angle value in 179°59.9’ E format. Also write a three-argument constructor.
 Write a main() program that displays an angle initialized with the constructor, and then, within a loop, allows the user to input any angle value, and then displays the value. You can use the hex character constant ‘\xF8’, which usually prints a degree (°) symbol..


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

using namespace std;

class angle{
private:
int degrees;
float minutes;
char direction;
public:
angle(int deg, float min, char dir){
degrees=deg;
minutes=min;
direction=dir;
}
void getAngle(int deg, float min, char dir){
degrees=deg;
minutes=min;
if(dir>96 && dir<124)
direction=dir-32;
else
direction=dir;
}
void disp() const {
cout << degrees << "\xF8" << minutes << "\'" << direction << endl;
}
};

int main(){
angle A(17, 31.5f, 'S');
int a; float b; char c;
A.disp();
cout<<"Enter degrees  : ";
cin>>a;
cout<<"Enter minutes  : ";
cin>>b;
cout<<"Enter direction: ";
cin>>c;
A.getAngle(a, b, c);
A.disp();
}


Start with the date structure  and transform it into a date class. Its member data should consist of three ints: month, day, and year. It should also have two member functions: getdate(), which allows the user to enter a date in 12/31/02 format, and showdate(), which displays the date.

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

using namespace std;

class date{
private:
int month, day, year;
char c;
public:
void setDate(){
cout << "Enter Date In This Format 31/12/1999" << endl;
cin >> day>>c>>month>>c>>year;
}
void getDate(){
cout << "Date Entered Is" << endl;
cout << day << c << month << c << year << endl;
}
};

int main(){
date d1;
d1.setDate();
d1.getDate();
}