Question2
#include <iostream>
using namespace std;
class CTriangle //declaring a class//
{
double *base,*height;//declaration of two pointers////private//
public :
CTriangle( double,double);//public////declaration of the constructor//
~CTriangle(); //declaration of the destructor//
double area()//method//
{
return(0.5* *base * *height);//formula to calculate the triangle area//
}
};
CTriangle::CTriangle( double b,double h)//Calling the constructor//
{
base= new double;
height= new double;
*base=b;
*height=h;
}
CTriangle::~CTriangle() //calling the destructor//
{
delete base;
delete height;
}
int main()//The main function//
{
CTriangle tria(3,4),triab(5,6);
cout<<"tria area: "<<tria.area()<<endl; //calling the method area//
cout<<"triab area: "<<triab.area()<<endl;
return 0;
} //closing the main function//
Question3
#include <iostream>
using namespace std;
int Daysapart(Date d1,Date d2);
{
int count=0;
Date temp;
if(d1>d2)
{
temp=d1;
d1=d2;
d2=temp;
}
assert:d1<=d2
while(!(d1==d2))
{
d1++;
count++;
}
return count;
}
int main()
{
date d1,d2;
int temp;
cout<<"Enter the first Date value:";
cin>>d1;
cout<<"Enter the second Date value:";
cin>>d2;
temp=Daysapart(d1,d2);
cout<<temp;
return 0;
}
Question4
//Name:K.Pooja//
//Student Id:20060788//
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
char myfile[100];
char newfile[100];
int i=0;
ifstream file;
file.open("exam.txt");
while(!file.eof())
{
file.getline(myfile,100);
cout<<setw(10)<<myfile;
i++;
}
file.close ();
cout<<"\n\n";
ofstream app;
app.open("exam.txt",ios::app);
app<<"Today is 9 May 2007";
app<<"Pooja is doing C++";
app.close();
ifstream file1;
file1.open("exam.txt");
while(!file1.eof())
{
file1.getline(newfile,100);
cout<<setw(10)<<newfile;
}
file1.close();
return 0;
}
|