Professional Documents
Culture Documents
Technology
COMPUTER SCIENCE DEPARTMENT
DSA (Lab)
Lab Task #01
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;;
Output:
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()
{
int DisplayTime()
{
cout<<"The Given Time in Seconds is = "<<total_sec;
}
};
int main()
{
Time t1;
t1.GetTime();
t1.timeInSec();
t1.DisplayTime();
}
Output:
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;
int main()
{ Student s1;
s1.GetIntro();
StudentResult s2;
s2.GetMark();
s2.TotalMarks();
s2.Perct();
return 0;
}
Output:
Lab Task # 4
Write a program to draw rectangle using loop.
Output: