You are on page 1of 8

S haheed Zulfikar Ali Bhutto Institute of Science &

Technology
COMPUTER SCIENCE DEPARTMENT

DSA (Lab)
Lab Task #01

Submitted To: Adil Majeed

Student Name: Syed Iqbal Hussain

Section: BS-SE (3B)

Reg. Number: 1980143

DSA-Lab BSSE-3B SZABIST-ISB


S haheed Zulfikar Ali Bhutto Institute of Science &
Technology

DSA-Lab BSSE-3B SZABIST-ISB


S haheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT

 Lab Task # 1
1. Write a program to find the sizes of data types
Char
Int
Short int
Long int
Float

Code:
#include <iostream>
using namespace std;
int main()
{
cout<<"\n The Sizes Of The Data Types "<<endl<<endl;;

cout<<"The Size of Char : "<<sizeof(char)<<endl;

cout<<"The Size of Int : "<<sizeof(int)<<endl;

cout<<"The Size of Short Int : "<<sizeof(short)<<endl;

cout<<"The Size of Long Int : "<<sizeof(long)<<endl;

cout<<"The Size of Float : "<<sizeof(float)<<endl;


return 0;
}

Output:

DSA-Lab BSSE-3B SZABIST-ISB


S haheed Zulfikar Ali Bhutto Institute of Science &
Technology

(Screenshot of your output screen)

 Lab Task # 2
Write a program to read time in HH:MM:SS format and convert into total seconds using class.

Code:
#include <iostream>
using namespace std;

class Time
{
public :
int hour,mint,sec,total_sec;

int GetTime()
{

cout<<"Enter The Hour : ";


cin>>hour;
cout<<"Enter The Mintue : ";
cin>>mint;
cout<<"Enter The Second : ";
cin>>sec;

DSA-Lab BSSE-3B SZABIST-ISB


S haheed Zulfikar Ali Bhutto Institute of Science &
intTechnology
timeInSec()
{
total_sec = hour*3600 + mint*60 + sec;

int DisplayTime()
{
cout<<"The Given Time in Seconds is = "<<total_sec;
}

};

int main()
{
Time t1;
t1.GetTime();
t1.timeInSec();
t1.DisplayTime();
}

Output:

(Screenshot of your output screen)

 Lab Task # 3
DSA-Lab BSSE-3B SZABIST-ISB
S haheed Zulfikar Ali Bhutto Institute of Science &
3. WriteTechnology
a program to read and print students information (Name, Age, Gender and Result
Information) using two classes and simple inheritance.

Code:
#include <iostream>
using namespace std;

class Student
{
public :
string name;
int age;
string gender;

void GetIntro()
{
cout<<"Enter Your Name ";
cin>>name;
cout<<"Enter Your Age ";
cin>>age;
cout<<"Enter Your Gender ";
cin>>gender;

};
class StudentResult :public Student
{

public :

int soft_Mang,data_str,hum_c_In,total_marks,pert1,pert2;

int GetMark()
{
cout<<"Enter Software Mangment System Marks ";
cin>>soft_Mang;
cout<<"Enter Data Structure & Algorithms Marks ";
cin>>data_str;
cout<<"Enter Human Computer Interaction Marks ";
cin>>hum_c_In;

}
int TotalMarks()
{
total_marks = hum_c_In + data_str + soft_Mang;
cout<<"Your Total Marks = "<<total_marks<<endl;
}
int Perct()
{
DSA-Lab BSSE-3B SZABIST-ISB
S haheed Zulfikar Ali Bhutto Institute of Science &
Technology pert1 = total_marks*100;
pert2 = pert1/300;

cout<<"Your Percentage = "<<pert2<<"%";


}
};

int main()
{ Student s1;
s1.GetIntro();
StudentResult s2;
s2.GetMark();
s2.TotalMarks();
s2.Perct();
return 0;
}

Output:

(Screenshot of your output screen)

 Lab Task # 4
Write a program to draw rectangle using loop.

DSA-Lab BSSE-3B SZABIST-ISB


S haheed Zulfikar Ali Bhutto Institute of Science &
Code:
Technology
#include <iostream>
using namespace std;
int main()
{
int size_of_Rect=15;
for(int i = 0 ; i<=size_of_Rect; i++)
{
for(int j =0 ; j<=size_of_Rect;j++)
{
if(i==0 || i==size_of_Rect || j==0 || j==size_of_Rect )
{
cout<<"*";
}
else
{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}

Output:

(Screenshot of your output screen)


DSA-Lab BSSE-3B SZABIST-ISB

You might also like