LAB 3 Solution
LAB 3 Solution
ANS. Time x;
3. Declare a variable of type Time, a pointer to Time and an array of 10 Times. Assign the
Address of the variable to the pointer.
4. Using pointer variable set the value of hour to 5, minute to 10 and second to 50.
5. Declare a structure Date. Declare another structure Project with fields: ID, startDate and
endDate. (Use nested structures).
PROGRAM
#include "stdafx.h"
#include<iostream> using
namespace std;
struct point
{ int x,y; };
void getinput(point &a)
{ cout<<"Enter the value for x"<<endl;
cin>>a.x;
cout<<"Enter the value for y"<<endl;
cin>>a.y; }
point addpoints(point p1, point p2)
{ point p3;
p3.x=p1.x+p2.x; p3.y=p1.y+p2.y;
return p3; }
int _tmain(int argc, _TCHAR* argv[])
{ point temp;
point a1,a2; getinput(a1);
getinput(a2);
temp=addpoints(a1,a2);
cout<<temp.x<<endl;
cout<<temp.y<<endl;
system ("pause"); return 0;
}
TASK 3:
i. Declare a structure Rectangle with two Points as its members, the top left and the bottom right.
ii.Declare a variable of type Rectangle and get user input for the two points.
iii. Define a function computeArea() which accepts a Rectangle and returns its area. iv. Display the
area of the Rectangle in the main().
PROGRAM
p1=(q.topleft.y*q.bottomright.x);
return p1; }
int _tmain(int argc, _TCHAR*
argv[])
{ int temp;
rectangle a1; a1.topleft.x=0;
a1.bottomright.y=0;
cout<<"Enter value for rectangle , for topleft y and bottom right x"<<endl;
cin>>a1.topleft.y>>a1.bottomright.x;
temp=compute_area(a1);
cout<<"THE AREA OF RECTANGLE WITH SIDES"<<a1.topleft.y<<" and
"<<a1.bottomright.x<<" = "<<temp;
system("pause");
return 0; }