c++ lab sheet kuppiya- 3

Lab Sheet 03

c++ වල source code පටන් ගන්නේ lab sheet 3න් .ඒකත් හිතන තරම් අමාරු නෑ
1. Write a program that prints following song in console window.

Twinkle, twinkle, little star,
How I wonder what you are.
Up above the world so high,
Like a diamond in the sky.

#include <iostream.h>

int main()
{
cout<<“Twinkle, twinkle, little star,”<<endl;
cout<<“How I wonder what you are.”<<endl;
cout<<“Up above the world so high,”<<endl;
cout<<“Like a diamond in the sky.”<<endl;
return 0;
}

2. Write a program that prints block letter B in 7×6 grid as follows.

*****
*          *
*          *
*****
*          *
*          *
*****

#include <iostream.h>

int main()
{
cout<<“*****”<<endl;
cout<<“*          *”<<endl;
cout<<“*         *”<<endl;
cout<<“*****”<<endl;
cout<<“*         *”<<endl;
cout<<“*         *”<<endl;
cout<<“*****”<<endl;
return 0;
}

3. Write a program to print following table using a single “cout” statement.

Year Income
____ ______
2001 7580.00
2002 4785.50
2003 9871.00

#include <iostream.h>

int main()
{
cout<<“Year Income\n”
“____ ______\n”
“2001 7580.00\n”
“2002 4785.50\n”
“2003 9871.00\n”;
return 0;

}

4. Write a program that print average and total of 3 numbers given by the user.

#include <iostream.h>

int main()
{
int a,b,c;
float total,average;
cout<<“Input No 1: “; cin>>a;
cout<<“Input No 2: “; cin>>b;
cout<<“Input No 3: “; cin>>c;
total=a+b+c;
average=total/3;
cout<<“Total is..: “<<total<<endl;
cout<<“Average is: “<<average<<endl;
return 0;
}

5. Write a program that prints the sum, difference, product, quotient and remainder of two integers that are input interactively.

#include <iostream.h>
int main(){

int on,tw,sum,d,e,f,g;
cout<<“inset first integer “; cin>>on;
cout<<“insert second integer”; cin>>tw;
sum=on+tw;
cout<<“The sum is “<<sum<<endl;
d=on-tw;
cout<<“differnce is “<<d<<endl;
e=on*tw;
cout<<“product is “<<e<<endl;
f=on/tw;
cout<<“quotient is “<<f<<endl;
g=on%tw;
cout<<“remainder is “<<g<<endl;

}

6. Write a program to convert temperature from Fahrenheit degrees to Celsius degrees.
Use the equation C = 5/9*(F-32), Where C is Celsius and F is Fahrenheit.

#include <iostream.h>

int main()
{
float f;
float c;
cout<<“Enter temperature in F: “; cin>>f;
c=(f-32)*5/9;
cout<<“Temperature in C: “<<c<<endl;
return 0;
}

7. Write a program to input amount that a customer purchases a certain good, and the tax rate (in percentage) of the good, and calculate the total amount that the customer should pay for this good, and print the sales tax rate and the total amount customer paid.
Hint: sales tax = amount of purchased x tax rate.

#include <iostream.h>

int main()
{
float pa;
float tr;
float tax;
float ta;
cout<<“Enter purchases amount……: “; cin>>pa;
cout<<“Enter Tax rate…………..: “; cin>>tr;
tax=pa*tr/100;
ta=tax+pa;
cout<<“Tax is………………….: “<<tax<<endl;
cout<<“Total amount of customer pay: “<<ta<<endl;
return 0;
}

8. Salesperson at a certain company gets an 8% commission on their sales. Write a program to input the amount that a person sold and output both the salesperson’s commission and the amount the company receives after the salesperson’s commission has been deducted.

#include <iostream.h>

int main()
{
float slamo;
float slpc;
cout<<“Enter Sold price………..: “; cin>>slamo;
slpc=slamo*8/100;
cout<<“Salesperson’s commission…: “<<slpc<<endl;
cout<<“Amount the company receives: “<<slamo-slpc<<endl;
return 0;
}

9. Write a program to converts mm to feet
Hint: – 25mm=1inch
12 inch=1feet

#include <iostream.h>

int main()
{
float mm;
cout<<“Input Lenth in mm: “; cin>>mm;
cout<<“The Lenth in feet: “<<mm/300<<endl;
return 0;
}

කුප්පිය ගැන ඔයාලගේ අදහස් යෝජනා පහලින් comment කරගෙනම යන්න..ස්තුතියි

378 thoughts on “c++ lab sheet kuppiya- 3

Leave a Reply

Your email address will not be published. Required fields are marked *