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

Lab 10

Name Muhammad Haseeb Ahsan

Roll Number 16F-8351

Section A1

Submitted to Sir Shahi Dost

Date 11/10/2016
Lab Practicing Tasks
Task1
#include<iostream>
using namespace std;
int main()
{
int start,rows,columns,i,j;
start=1;
cout<<"Enter number of ROWS=";
cin>>rows;
cout<<"Enter number of COLUMNS=";
cin>>columns;
for(i=1;i<=rows;i++)
{
for(j=1;j<=columns;j++)
{
cout<<start<<" \t";
start=start++;
}
cout<<endl;
}
system("pause");
return 0;
}
Task2
#include<iostream>
using namespace std;
int main()
{
int start,i,j;
start=1;
cout<<" MON TUES WED THUR FRI SAT SUN"<<endl;
for(i=1;i<=5;i++)
{
for(j=1;j<=7;j++)
{
if(start == 32)
{
break;
}
cout<<start<<" \t";
start=start++;
}
cout<<endl;
}
system("pause");
return 0;
}
Task3
#include<iostream>
#include<cmath>
using namespace std;

int main ()
{
int year, start_day, type, n_days, month(1);
cout << "Enter the year you want to display = ";
cin >> year;
cout << "\nEnter the first day of January:\n1 for Sunday, 2 for Monday, etc. ";
cin >> start_day;
while (start_day < 0 || start_day > 12)
{
cout << "\nThe number entered is invalid.\nPlease enter a number between 1
and 7. ";
cin >> start_day;
}

while (month <= 12)


{
switch (month)
{
case 1:
cout << "\n\nJanuary\n" << endl;
n_days = 31;
break;
case 2:
cout << "\n\nFebruary\n" << endl;
if (type = 1)
{
n_days = 29;
}
else
{
n_days = 28;
}
break;
case 3:
cout << "\n\nMarch\n" << endl;
n_days = 31;
break;
case 4:
cout << "\n\nApril\n" << endl;
n_days = 30;
break;
case 5:
cout << "\n\nMay\n" << endl;
n_days = 31;
break;
case 6:
cout << "\n\nJune\n" << endl;
n_days = 30;
break;
case 7:
cout << "\n\nJuly\n" << endl;
n_days = 31;
break;
case 8:
cout << "\n\nAugust\n" << endl;
n_days = 31;
break;
case 9:
cout << "\n\nSeptember\n" << endl;
n_days = 30;
break;
case 10:
cout << "\n\nOctober" << endl;
n_days = 31;
break;
case 11:
cout << "\n\nNovember" << endl;
n_days = 30;
break;
case 12:
cout << "\n\nDecember\n" << endl;
n_days = 31;
break;
default:
;
}

cout << endl << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";


for (int i = 1; i < start_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{
if (((j + start_day - 2) % 7 == 0) && (j != 1))
cout << endl;
cout << j << "\t";
}
cout << endl << endl;

month ++;

}
system("pause");

return 0;
}
Lab Tasks
Task1
#include<iostream>
using namespace std;
int main()
{
int time,distance,avgspeed;
cout<<"As Average speed=55"<<endl;
cout<<"time=4"<<endl;
cout<<"distance=0"<<endl;
avgspeed=55;
time=4;
int i=1;
while (i<=4)
{
distance=avgspeed*i;
cout<<"The Car has travelled after "<<i<<" hours is "<<distance;
cout<<endl;
i++;
}
system("pause");
return 0;
}
Task2
#include<iostream>
using namespace std;
int main()
{
int age,i;
age=12;
i=10;
while (i<=1280)
{
cout<<"Gift of "<<i<<"$ is"<<endl;
cout<<"At the Age of "<<age<<endl;
age=++age;
i=i*2;
cout<<endl;
}
system("pause");
return 0;
}
Task3
#include<iostream>
using namespace std;
int main()
{
int n,result,num,i;
cout<<"Enter the value of n=";
cin>>n;
cout<<"How many time will it run=";
cin>>num;
cout<<endl;
cout<<endl;
cout<<"Initializa Result=1"<<endl;
result=2;
for (i=1;i<=num;i++)
{
cout<<"Accumulate Result of 2n="<<result<<endl;
result=result*n;
}
system("pause");
return 0;
}
Task4
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout << "Please Enter Any Number =";
cin >> a;
cout << endl;
if (a > 0)
{
cout << "Reverse Number=";
do
{
b=a % 10;
cout<<b;
a=a / 10;
}
while (a > 0);
cout<<endl;
}
else
{
cout<<"This is a Negative Number.\nPlease Enter another Number"<<endl;
}
system("pause");
return 0;
}
Task5
#include<iostream>
using namespace std;
int main()
{

double x,y,z;
int avg;
int i = 1;
while (i <= 5)
{
cout <<"For Generator "<<i<<endl;
cin >> x;
cin >> y;
cin >> z;
avg = (x + y + z) / 3;
cout << "Average voltage for Generator "<<i<<" = "<< avg<<endl;
cout << endl;
i=i++;
}
system("pause");
return 0;
}
Task6
#include<iostream>
using namespace std;
int main()
{

int x,y;
y = 1;
while (y <= 3)
{
cout << "Please Enter a Number = ";
cin >> x;
x = x * 7;
x = x * 11;
x = x * 13;
cout << "Answer of this Number is "<< x << "\n";
cout<<endl;
y=y++;
}

system("pause");
return 0;
}
The End

You might also like