University of Agriculture Faisalabad T.T Singh: Introducton To Programming Assignment No. 1&2 1 Semmester CS - 303
University of Agriculture Faisalabad T.T Singh: Introducton To Programming Assignment No. 1&2 1 Semmester CS - 303
T.T SINGH
INTRODUCTON TO PROGRAMMING
1ST SEMMESTER
CS_303
2015-ag-7968
ASSIGNMENT
NO.1
1 .program for the grading of marks by ' if else statement '
#include<iostream>
using namespace std;
void main()
{
int marks;
cout<<"Enter Student Marks :";
cin>>marks;
if(marks>=90)
cout<<"Student have grade A"<<endl;
else if(marks>=80)
cout<<"Student have Grade B"<<endl;
else if(marks>=70)
cout<<"Student have Grade C"<<endl;
else if(marks>=60)
cout<<"Student have Grade D<<endl";
else if(marks>=50)
cout<<"Student have Grade E"<<endl;
else
cout<<"Fail"<<endl;
system("pause");
}
Output
2. Find the largest number using if statement
#include<iostream>
using namespace std;
void main()
{
Int n1, n2, n3;
cout << "Enter 1 numbers: ";
cin >> n1;
cout << "Enter 2 numbers: ";
cin >> n2;
cout << "Enter 3 numbers: ";
cin >> n3;
system("pause");
}
output
3. Find the smallest number using if statement
#include<iostream>
using namespace std;
void main()
{
int n1,n2,n3;
cout<<"Enter 1 values"<<endl;
cin>>n1;
cout<<"Enter 2 values"<<endl;
cin>>n2;
cout<<"Enter 3 values"<<endl;
cin>>n3;
if(n1<n2 && n1<n3)
cout<<"smallest value is:"<<n1<<endl;;
if(n2<n1 && n2<n3)
cout<<"Smallest value is:"<<n2<<endl;
else
cout<<"smallest value is:"<<n3<<endl;
system("pause");
}
Output
4. Find the ASCII value of given character
#include<iostream>
using namespace std;
void main()
{
char ASCII;
cout << "Enter a character: ";
cin >> ASCII;
cout << "ASCII VALUEVALUE IS:" << (int)ASCII << endl;
system("pause");
}
OUTPUT
5. Find grade using ‘case statement’
#include<iostream>
using namespace std;
void main()
{
int marks;
char grade;
switch(marks/10)
{
case 10: grade='A';
break;
case 9: grade='A';
break;
case 8: grade='A';
break;
case 7 : grade='B';
break;
case 6: grade='C';
break;
case 5: grade='D';
break;
default : grade='F';
}
int min_star=1,p_height=4,p_space=p_height-1;
for( int i=0;i<p_height;i++)
{
for(int j=p_space;j>i;j--)
{cout<<" ";}
for(int k=0;k<min_star;k++)
{cout<<"@";}
min_star+=2;
cout<<endl;
}
system("pause");
}
OUTPUT
2. PRINT
1
21
321
4321
54321
CODE:
#include<iostream>
using namespace std;
void main()
{
{
int z=1,k,n=5;
for(int a=1;a<=n;a++)
{
for(int k=n-1;k>=a;k--)
{cout<<" ";}
for(int b=z;b>=1;b--)
{cout<<b;}
z++;
cout<<endl;
}
}
system("pause");}
OUTPUT
3.PRINT A DIAMOND
CODE:
#include<iostream>
usingnamespacestd;
int main()
{
for(int a=0;a<1;a++)
{cout<<" *";}
cout<<endl;
for(int i=2;i<=3;i++)
{cout<<" ";
for(int j=i;j<3;j++)
{cout<<" ";}
for(int k=0;k<=i-1;k++)
{cout<<"* ";}
if(i==3)
{cout<<"* ";}
cout<<" ";
cout<<endl;
}
for(int i=2;i>=1;i--)
{cout<<" ";
for(int j=3;j>i;j--)
{cout<<" ";}
for(int k=i;k>=1;k--)
{cout<<" *";}
cout<<endl;
}
system("pause")
}
OUTPUT
Second number is the square of fiest number
Code:
#include<iostream>
using namespace std;
void main()
{
int a,b;
cout<<"enter the number 2"<<endl;
cin>>a>>b;
if(a*a==b)
{
cout<<"second no. is the square of first number"<<endl;
}
system("pause");
output
Bill
#include<iostream>
using namespace std;
void main()
{
int units;
float bill;
if(units<=300)
{bill= units*2;}
else if(units<=500)
{bill= units*5;}
else
{bill= units*7;}
bill=bill+150;
if(bill>2000)
{bill=bill+(bill*5/100);}
cout<<bill<<"bill is:";
system("pause");
}
THE END