0% found this document useful (0 votes)
61 views22 pages

ASSIGNMENT (Mini)

The document contains 13 programming assignments submitted by Sidra Bashir. Each assignment contains C++ code to solve various problems involving arrays such as inputting values into arrays, calculating sums and averages, comparing values, and more. The code includes functions for input, output, loops, if/else statements, and arrays.

Uploaded by

Sarah Fatima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views22 pages

ASSIGNMENT (Mini)

The document contains 13 programming assignments submitted by Sidra Bashir. Each assignment contains C++ code to solve various problems involving arrays such as inputting values into arrays, calculating sums and averages, comparing values, and more. The code includes functions for input, output, loops, if/else statements, and arrays.

Uploaded by

Sarah Fatima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

ASSIGNMENT

PROGRAMMING
FUNDAMENTALS
Submitted By:
Sidra Bashir
BT 15012
Submitted To:
Sir Irfan Ahmed
//PROGRAM 1 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main(){

clrscr():

int arr[5];

cout<<" Enter first value : ";

cin>>arr[0];

cout<<" Enter second value : ";

cin>>arr[1];

cout<<" Enter third value : ";

cin>>arr[2];

cout<<" Enter fourth value : ";

cin>>arr[3];

cout<<" Enter fifth value : ";

cin>>arr[4];

getch();

clrscr();

cout<<" ********************************* "<<endl;

cout<<" The entered values in array are : "<<endl;

cout<<" ********************************* "<<endl;

cout<<" "<<arr[0]<<endl;

cout<<" "<<arr[1]<<endl;

cout<<" "<<arr[2]<<endl;

cout<<" "<<arr[3]<<endl;
cout<<" "<<arr[4]<<endl;

cout<<endl;

cout<<" ********************************* "<<endl;

getch();}

//PROGRAM 2 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main(){

clrscr();

int arr[5],i;

for(i=0; i<5; i++)

{
cout<<" Enter an integer : ";

cin>>arr[i];

cout<<" Values in array are : "<<endl;

cout<<" ******************************** "<<endl<<endl;

for(i=0; i<5; i++)

cout<<" "<<arr[i]<<endl;

cout<<" ******************************** "<<endl;

getch();

}
//PROGRAM 3 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int arr[5],i,sum=0;

float avg;

cout<<" SUM AND AVERAGE CALCULATOR "<<endl;

cout<<" ********************************* "<<endl;

for(i=0; i<5; i++)

cout<<" Enter an value : ";

cin>>arr[i];

sum=sum+arr[i];

avg=sum/5.0;

cout<<" Sum is : "<<sum<<endl;

cout<<" Average is : "<<avg<<endl;

getch();}
//PROGRAM 4 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int day,i,total,month;

int days_per_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

cout<<" ******************************* "<<endl;

cout<<" DAYS CALCULATOR "<<endl;

cout<<" ******************************* "<<endl;

cout<<" Enter month number : ";

cin>>month;

cout<<" Enter day number : ";

cin>>day;
total=day;

for(i=0; i<month-1; i++)

total=total+days_per_month[i];

cout<<" Total number of days in year till date = "<<total<<endl;

getch();

//PROGRAM#5 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main(){

clrscr();

int age[100],i,n,count=0;

cout<<" ******************************** "<<endl;


cout<<" AGE CALCULATOR "<<endl;

cout<<" ******************************** "<<endl;

cout<<" Enter the number of persons required : ";

cin>> n;

cout<<" Enter the ages of "<<n<<" persons : “;

for(i=0; i<=n; i++){

cout<<" ";

cin>>age[i];

if(age[i]>=50 && age[i]<=60)

count=count+1;}

cout<<" "<<count<<" Persons are between 50 and 60 : "<<endl;

getch();

//PROGRAM #6 R.BT15012 N.B.Sidra S.A.M


#include<iostream.h>

#include<conio.h>

void main(){

clrscr();

const int size=5;

int numbers[size];

int squares[size];

int cubes[size];

int sum[size];

int i,total=0;

for(i=0; i<size; i++){

numbers[i]=i;

squares[i]=i*i;

cubes[i]=i*i*i;

sum[i]=numbers[i]+squares[i]+cubes[i];}

cout<<" **************************************************"<<endl;

cout<<" Numbers "<<"\t";

for(i=0; i<size; i++){

cout<<numbers[i]<<"\t";}

cout<<" Squares "<<"\t";

for(i=0; i<size; i++)

cout<<squares[i]<<"\t";

cout<<" Cudes "<<"\t";


for(i=0; i<size; i++){

cout<<cubes[i]<<"\t";}

cout<<" Sum "<<"\t";

for(i=0; i<size; i++){

cout<<sum[i]<<"\t";

total=total+sum[i];}

cout<<" Total is : "<<total<<endl;

cout<<" **************************************************"<<endl;

getch();

//PROGRAM #7 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main()

clrscr();
int arr[10],i,max;

cout<<" DISPLAY MAXIMUM NUMBER "<<endl;

cout<<" ********************************** "<<endl;

for(i=0; i<10; i++){

cout<<" Enter a number = ";

cin>>arr[i];}

max=arr[0];

for(i=0; i<10; i++){

if( max < arr[i] )

max=arr[i];}

cout<<" Maximum value is : "<<max<<endl;

getch();}

//PROGRAM #8 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>
void main()

clrscr();

int arr[10],i,min;

cout<<" DISPLAY MINIMUM NUMBER "<<endl;

cout<<" ********************************** "<<endl;

for(i=0; i<10; i++)

cout<<" Enter a number = ";

cin>>arr[i];

min=arr[0];

for(i=0; i<10; i++)

if( min > arr[i] )

min=arr[i];

cout<<" Minimum value is : "<<min<<endl;

getch();

}
//PROGRAM 9 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int arr[5],i,num;

cout<<" NUMBER IN REVERSE AND ACTUAL ORDER "<<endl;

cout<<" ****************************************** "<<endl<<endl;

for(i=0; i<5; i++)

{
cout<<" Enter a number = ";

cin>>arr[i];}

cout<<" Number in actual order: ";

for(i=0; i<5; i++){

cout<<arr[i]<<" ";}

cout<<" Number in reverse order: ";

for(i=4; i>=0; i--)

cout<<arr[i]<<" ";

getch();}

//PROGRAM 10 R.BT15012 N.B.Sidra S.A.M

#include<iostream.h>
#include<conio.h>

void main()

clrscr();

int arr[10]={10,20,30,40,50,60,70,80,90,100};

int i,n,loc=-1;

cout<<" ******************************** "<<endl;

cout<<" Enter value to find = ";

cin>>n;

for(i=0; i<10; i++)

if(arr[i]==n)

loc=i;

if(loc==-1)

cout<<" Value not found in array : "<<endl;

else

cout<<" Value found in andex at : "<<loc<<endl;

cout<<" ********************************"<<endl;

getch();

}
//PROGRAM#11 R.BT15012 N.BT15012 S.A.M

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

cout<<endl<<endl;

cout<<" PROGRAM TO ENTER AGE OF PERSONS "<<endl;

cout<<" AND THEN DISPLAYING HOW MANY ARE ABOVE FIFTY "<<endl;

cout<<"******************************************************************"<<endl<<endl;

int n,i,age[500],count=0;

cout<<" HOW MANY PERSONS ARE REQUIRED = ";

cin>>n;

for(i=0;i<n;i++)

cout<<" ENTER AGE OF A PERSON = ";


cin>>age[i];

if(age[i]>50)

count++;

cout<<" FINAL RESULT "<<endl<<endl;

cout<<" ****************************************** "<<endl;

cout<<" "<<count<<" persons are above 50 "<<endl<<endl;

cout<<"*******************************************************************";

getch();

//PROGRAM#12 R.BT15012 N.B.SIDRA S.A.M

#include<iostream.h>

#include<stdlib.h>

#include<conio.h>

void main()

clrscr();

int b_date,b_month,b_year;

int c_date,c_month,c_year;

int b_arr[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int c_arr[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int total,current_days,umr,age,child,i,j,old,y,count=0;

cout<<" Age Calculator "<<endl;

cout<<"***************************************"<<endl<<endl;

cout<<" Enter Birth Date : ";


cin>>b_date;

if(b_date<1 && b_date>31)

cout<<" Restart the program and enter days 1 to 31 ";

getch();

exit(0);}

cout<<" Enter Birth Month : ";

cin>>b_month;

if(b_date<1 && b_date>12)

cout<<" Restart the program and enter month 1 to 12 ";

getch();

exit(0);

cout<<" Enter Birth Year : ";

cin>>b_year;

cout<<" Your date of birth is "<<b_date<<"-"<<b_month<<"-"<<b_year<<endl;

cout<<" Enter Current Date : ";

cin>>c_date;

cout<<" Enter Current Month: ";

cin>>c_month;

cout<<" Enter Current Year : ";

cin>>c_year;

cout<<" Current date is "<<c_date<<"-"<<c_month<<"-"<<c_year<<endl;

old=b_date-1;
for(i=0;i<b_month-1;i++)

old+=b_arr[i];

child=365-old;

age=c_year - b_year - 1;

for(y=b_year;y<=c_year;y++)

if(y%4==0)

count++;

umr=365*age;

current_days=c_date-1;

for(j=0;j<c_month-1;j++)

current_days+=c_arr[i];

total=current_days+umr+child+count;

cout<<"Birth Date : "<<b_date<<"-"<<b_month<<"-"<<b_year<<endl;

cout<<"Current Date: "<<c_date<<"-"<<c_month<<"-"<<c_year<<endl;

cout<<"___________________________________________"<<endl<<endl;

cout<<"You Have Spend : " << total << " Days till Now."<<endl;

cout<<"___________________________________________"<<endl;

getch();}
//PROGRAM#13 R.BT15012 N.B.SIDRA S.A.M

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

cout<<endl<<endl;

cout<<"_______________PROGRAM TO ENTER AGE OF PERSONS____________________"<<endl;


cout<<"____________CREATED BY SIDRA BASHIR BT15012 SECTION
A________________"<<endl<<endl;

cout<<"******************************************************************"<<endl<<endl;

int n,i,age[500],count1=0,count2=0,count3=0,count4=0;

cout<<" HOW MANY PERSONS ARE REQUIRED = ";

cin>>n;

for(i=0;i<n;i++)

cout<<" ENTER AGE OF A PERSON = ";

cin>>age[i];

if(age[i]>=45)

count1++;

else if(age[i]>=20&&age[i]<=44)

count2++;

else if(age[i]>=13&&age[i]<=19)

count3++;

else

count4++;

clrscr();

cout<<"____________________THE FINAL RESULT____________________________"<<endl<<endl;

cout<<"******************************************************************"<<endl<<endl;

cout<<" "<<count1<<" persons are old "<<endl;

cout<<" "<<count2<<" persons are young "<<endl;

cout<<" "<<count3<<" persons are teenagers "<<endl;

cout<<" "<<count4<<" persons are child "<<endl<<endl<<endl;


cout<<"*******************************************************************";

getch();

You might also like