Sunday, 3 July 2016

Problems

Write a program that prompts the user to input a length expressed in centimeters. The program should then convert the length to inches (to the nearest inch) and output the length expressed in yards, feet, and inches, in that order. For example, suppose the input for centimeters is 312. To the nearest inch, 312 centimeters is equal to 123 inches. 123 inches would thus be output as: 3 yard(s), 1 feet (foot), and 3 inch (es)...................................


#include<iostream>
using namespace std;
int main()
{
       int a;
       int b;
       int c;
       int d;
       int e;
       int f;
       cout << "Enter Length(in centimeters)" << endl;
       cin >> a;
       cout << "Length ="<<a<<"cm"<<endl;
       b=(a/25)*10;
    cout << "Length ="<<b<<"inches"<<endl;
       c=b/12;
       d=b%12;
       e=c/3;
       f=c%3;
       cout <<"Lenth=" <<e<<"yards(s)"<<f<<"feet(foot)"<<d<<"inch(es)"<<endl;
       system("pause");
       return 0;
}
To make a profit, a local store marks up the prices of its items by a certain percentage. Write a C++ program that reads the original price of the item sold the percentage of the marked-up price, and the sales tax rate. The program then outputs the original price of the item, the percentage of the mark-up, the store’s selling price of the item, the sales tax rate, the sales tax, and the final price of the item....


#include<iostream>
using namespace std;
int main()
{
       int a;
       int b;
       int c;
       int d;
       int e;
       int f;
       cout << "Enter original price of item ="<<endl;
       cin >> a;
       cout << "percentage of the mark up="<<endl;
       cin >> b;
       c= b*a/100;
       cout << "mark up amount="<< c <<endl;
       cout << "percentage of the sales tax rate="<<endl;
       cin >> d;
       e = d*a/100;
       cout << "tax amount amount="<< e <<endl;
       f = a + c + e;
       cout << "price of item="<< f <<endl;
       system("pause");
       return 0;

}

Write a C++ program that prompts the user to input the elapsed time for an event in hours, minutes, and seconds. The program then outputs the elapsed time in seconds..........


#include<iostream>
using namespace std;
int main()
{
       int a;
       int b;
       int c;
       int d;

    cout <<"houres="<<endl;
    cin>>a;
       cout <<"minutes="<<endl;
       cin>>b;
       cout <<"seconds="<<endl;
       cin>>c;
       cout <<"time Elapsed(in houres,minutes,seconds)="<<a<<":"<<b<<":"<<c<<endl;
       d=3600*a + 60*b +c;
       cout <<"time Elapsed(in seconds)"<< d <<endl;
       system("pause");
       return 0;

}
Write a C++ program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example, if the elapsed time is 9630 seconds, then the output is 2:40:30.).............


#include<iostream>
using namespace std;
int main()
{
       int a;
       int b;
       int c;
       int d;
       int e;
       cout << "Enter time Elapsed(in seconds)" << endl;
       cin >> a;
       b=a/60;
       c=a%60;
       d=b/60;
       e=b%60;
       cout <<"time Elapsed(houres,minutes,seconds)=" <<d<<":"<<e<<":"<<c<<endl;
       system("pause");
       return 0;

}

Write a program that prompts the capacity, in gallons, of an automobile fuel tank and the miles per gallons the automobile can be driven. The program outputs the number of miles the automobile can be driven without refueling.....


#include<iostream>
using namespace std;
int main()
{
       int a;
       int b;
       int c;
       cout << "Enter Automobile fuel tank capacity(in gallons)" <<endl;
       cin >> a;
       cout << "Fuel tank capacity =" << a <<endl;
       cout << "Enter miles per gallon can car drive" <<endl;
       cin >> b;
       cout << "miles per gallon =" << b <<endl;
       c = a*b;
       cout << "number of miles driven without refueling =" << c <<endl;
       system("pause");
       return 0;

}
Papal Tea Company wants a program that allows a clerk to enter the number of pounds of tea ordered, the price per pound, and whether the customer should be charged a $15 ,or $25 shipping fee and 30$ or 40$ rent charges. The program should calculate and display the total amount the customer consumed......

#include<iostream>
using namespace std;
const int p = 10;
int main()
{
       int a;
       int b;
       int c;
       int d;
       cout << "amount per pound =" << p <<endl;
       cout << "Enter amount of tea" <<endl;
       cin >> a;
       cout << "amount of tea =" << a <<endl;
       cout << "Enter shipping fee 15$ or 25$ " <<endl;
       cin >> b;
       cout << "shipping fee =" << b <<endl;
       cout << "Enter rent charges 30$ or 40$ " <<endl;
       cin >> c;
       cout << "rent charges =" << c <<endl;
       d = (p * a) + b + c;
       cout << "total charges =" << d <<endl;
       system("pause");
       return 0;

}
Print the diamond shape using nested loops in a logical way.
//program to make Diamond.
#include<iostream>
using namespace std;
int main()
{
       int a,b,c;
       cout<<"Enter Size of Diamond= ";
       cin>>a;
       for (b=0;b<a;b++)
       {
              for(c=a;c>b;c--)
              {
                     cout<<" ";
              }
              for (c=0;c<=b;c++)
              {
                     cout<<"* ";
              }
              cout<<endl;
       }
       for (b=0;b<a;b++)
       {
              for(c=0;c<=b;c++)
              {
                     cout<<" ";
              }
              for (c=(a-1);c>b;c--)
              {
                     cout<<" *";
              }
              cout<<endl;
       }
              system("pause");
       return 0;
}
Write a program to calculate the sum & average of ten-numbers using two variables only....???

//Program to sum and Avg of Ten Numbers using Two variables.
#include<iostream>
using namespace std;
int main()
{
       do
uble i,sum=0,a;
       for(i=0;i<10;i++)
       {
              cout<<"Enter Numbers"<<endl;
              cin>>a;
              sum=sum+a;
       }
       sum/10;
       cout<<"Sum of Numbers="<<sum<<endl;
       cout<<"Avg of Numbers="<<sum/10<<endl;
       system("pause");
       return 0;


}


Write a program that reads in the size of a square and print a hollow square of that size out of asterisk and blanks. Your program should work for squares of size between 1 and  20. For example, if your program reads a size of 7, it should print.
//program to make square.

#include<iostream>
using namespace std;
int main()
{
       int a,b,c;
       cout<<"Enter a size of rectangle=";
       cin>>a;
       if (a<=20)
       {
       for(b=0;b<a;b++)
       {
              cout<<"*";
       }
       cout<<"\n";
       for(b=0;b<(a-2);b++)
       {
       for(c=0;c<1;c++)
       {
              cout<<"*";
       for(c=0;c<(a-2);c++)
       {
              cout<<" ";
       }
       for(c=0;c<1;c++)
       {
              cout<<"*";
       }
       }
       cout<<"\n";
       }
       for (c=0;c<a;c++)
       {
              cout<<"*";
       }
       cout<<"\n";
       }
       else
       {
              cout<<"out of range"<<endl;
       }
       system("pause");
       return 0;
}
Input two numbers from the user and swap their values...????
//program to Swap the values of two input numbers
#include<iostream>
using namespace std;
int main()
{
       int a,b,c;
       cout<<"Enter first Number"<<endl;
       cin>>a;
    cout<<"first Number="<<a<<endl;
       cout<<"Enter second Number"<<endl;
       cin>>b;
    cout<<"second Number="<<b<<endl;
       c=a;
       a=a-a;
       a=a+b;
       b=b-b;
       b=b+c;
       cout<<"first Number="<<a<<endl;
       cout<<"second Number="<<b<<endl;
       system("pause");
       return 0;
}
Write a program that finds out whether a number is perfect number or not using a
function. A number is said to be perfect if the sum of all its devisors except the number

itself is equal to the number. (Hint: 6 is a perfect number since 6 = 1+2+3). 
#include<iostream>
using namespace std;
int perfect(int);
int main ()
{
       int a,b;
       cout<<"Enter Number= ";
       cin>>a;
       b=perfect(a);
       if (b==a)
       {
              cout<<"Perfect Number"<<endl;
       }
       else
       {
              cout<<"Not perfect Number"<<endl;
       }
       system("pause");
       return 0;
}
int perfect(int x)
{
       int sum=0;
       for(int i=1;i<x;i++)
       {
              if (x%i==0)
              {
                     sum=sum+i;
              }
       }
       return sum;

}

No comments:

Post a Comment