Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Assignment # 01

Object Oriented Programming


LAB

Students Name: Mashal Khalil

Instructor: Mr. M. S. Zafar

Date: 31 March 2021


Task Title:
Write a C++ program to check if a given year is leap year or not:

Code:
#include<iostream>

using namespace std;

int main()

int year;

cout<<"\n Enter year :";

cin>>year;

if(year%400==0 || year%100!=0 && year%4==0)

cout<<"\n Leap year :";

else

cout<<"\n Not a Leap year :";

return 0;

OUTPUT:
Task Title:
Write a program to find size of int, float and double variable

Code:
#include<iostream>

using namespace std;

int main()

int sint,sfloat,sdouble;

sint=sizeof(int);

sfloat=sizeof(float);

sdouble=sizeof(double);

cout<<"\n Size of Int :"<<sint;

cout<<"\n Size of float :"<<sfloat;

cout<<"\n Size of double :"<<sdouble;

return 0;

OUTPUT:
Task Title:
Write a Program to print half pyramid a using mmhg uygt numbers:

Code:
#include<iostream>

using namespace std;

int main()

for(int i=1;i<=5;i++)

for(int j=1;j<=i;j++)

cout<<i;

cout<<"\n";

return 0;

OUTPUT:
Task Title:
 Write a Program to store value of two books in structure and then display it. (Book ID,
Book Name, Book Author, Book Subject):

Code:
Book.h:

struct Book

int Id;

char Name[50];

char Authorname[50];

char Subject[50];

};

Book.cpp

#include"Book.h"
#include<iostream>
using namespace std;
int main()
{
Book b1[50];
for(int i=0;i<2;i++)
{
cout<<"\n Enter the Id of Book: ";
cin>>b1[i].Id;
cout<<"\n Enter the Name of Book: ";
cin>>b1[i].Name;
cout<<"\n Enter the Name of Author of Book: ";
cin>>b1[i].Authorname;
cout<<"\n Enter the Subject of Book: ";
cin>>b1[i].Subject;
}
cout<<"\n __________________________________________ :";
for(int i=0;i<2;i++)
{
cout<<"\n Displaying Data :";
cout<<b1[i].Id<<endl;
cout<<b1[i].Name<<endl;
cout<<b1[i].Authorname<<endl;
cout<<b1[i].Subject<<endl;
}
return 0;
}
OUTPUT:
Task Title:
Store Information of student in a Structure and Display it. Student information should
contain his Name, Roll Number and Marks.

Code:
Student.h:
struct Student
{
int Rollno;
char Name[50];
int marks;
};
Student.cpp:
#include"Student.h"
#include<iostream>
using namespace std;
int main()
{
Student std;
cout<<"\n Enter the Roll no of student :";
cin>>std.Rollno;
cout<<"\n Enter the Name of student :";
cin>>std.Name;
cout<<"\n Enter the marks of student :";
cin>>std.marks;
cout<<"\n_______________________________\nDisplaying data:";
cout<<"\n Roll no:"<<std.Rollno;
cout<<"\n Name :"<<std.Name;
cout<<"\n Marks :"<<std.marks;
return 0;
}
OUTPUT:

You might also like