Programming Fundamentals Lab 1

Posted on at


 

 

 

Programming Fundamentals Lab

Expeirment.No.1:
Source Code:
//Data Type Initialization:
#include<iostream>
#include<conio.h>
void main()
{
int units = 5;
float price = 12.5;
double idnumber = 12583;
double cost = price*units;
cout << idnumber << " " << units << " " << price << " " << cost << endl;
double tax = cost*0.06;
double total = cost + tax;
cout << tax << " " << total << endl;
getch();
}

Experiment.No.2:
Source Code:
#include<iostream>
#include<conio.h>
void main( )
{
const float PI=3.14159;
float radius = 5;
float area;
area = radius * radius * 3.14159; // Circle area calculation
cout << "The area is " << area << " with a radius of 5.\n";
radius = 20; // Compute area with new radius.
area = radius * radius * 3.14159;
cout << "The area is " << area << " with a radius of 20.\n";
getch();
}

OUTPUT:
Experiment.No.3(a):
Source Code:
//Program For Arithematic Calculation:
# include <iostream>
#include<iostream.h>
void main()
{
float Answer=1 + 2 * 4 / 2;
cout<<"Answer is:"<<Answer;

getch();
}

 

Experiment.No.3(b):
Source Code:
//Program For Arithematic Calculation:
# include <iostream>
#include<conio.h>
void main()
{
float Answer=(1 + 2) * 4 / 2;
cout<<"Answer is:\n"<<Answer;
getch();
}



Experiment.NO.3(c):
Source Code:
//Program For Arithematic Calculation:
# include <iostream>
#include<conio.h>
void main()
{
float Answer=1 + 2 * (4 / 2);
cout<<"Answer is:\n"<<Answer;
getch();
}



Experiment.No.3(d):
Source Code:
//Program For Arithematic Calculation:
# include <iostream>
#include<conio.h>
void main()
{
float Answer=9 % 2 + 1;
cout<<"Answer is:\n"<<Answer;
getch();
}


Experiment.No.3(e):
Source Code:
//Program For Arithematic Calculation:
# include <iostream>
#include<conio.h>
void main()
{
float Answer= (1 + (10 - (2 + 2)));
cout<<"Answer is:\n"<<Answer;
getch();
}


Experiment.No.4 (a):
Source Code:
//Program for seeing the size of smthg....

#include<iostream>
#include<conio.h>
void main()
{
short i = -3;
unsigned short u;
cout<< sizeof(i)<<endl ;
cout<<sizeof(u)<<endl;
cout << (u = i) <<endl;
getch();
}


Explanation:
First we assign the short Int to I whose size is 2 Byte. Then We Assign the Int U as unsigned, which has size of 2 Bytes having only positive value.
When we assign the value of I to U as U=I, then we will get A Garbage value as U has no negative value and I=-3.
So, that’s why we get the garbage value.
Experiment.No.4 (b):
Source Code:
#include<iostream>
#inlcude<conio.h>
void main()
{
int i = 125*4/10;
cout << i << "\n";
getch();
}


Exercise.no.1:
Source Code:
//Program Showing the Circumference:
# include <iostream>
#include<conio.h>
void main()
{
int r=5;
cin>>r;
float pi=3.1416;
float circumference;
circumference=2*pi*r;
cout<<"circumference is:"<<circumference;
getch();
}


Exercise.no.2:
Source Code:
//Program Calculating The Total Money Annual Intrest:

# include <iostream>
#include<conio.h>
void main()
{
double P;
cin>>P;
long int N;
cin>>N;
double R=0.07;
double Amount=P*(1 + R)*N;
cout<<"Total Amount you Got:\n"<<Amount;
getch();
}


Exercise.no.3:
//Program Calculating Temperature In Celcius:
# include <iostream>
#include<conio.h>
void main()
{
double f;
cin>>f;
long double Celcius=5/9*(f -32);
cout<<"Temperature In Celcius:\n"<<Celcius;
getch();
}

 

 



About the author

Saif-Filmannex

I am doing Bs Electronics Engineering from International Islamic University

Subscribe 0
160