/**1. Assuming there are 7.481 gallons in a cubic foot, write a program that asks the user to enter a
number of gallons, and then displays the equivalent in cubic feet.*/
#include<iostream.h>
#include<conio.h>
#define g_per_f 7.481
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"-------------------------------------------------------------------------------\n\n";
float n_gallons;
do{
cout<<"Enter the number of gallons : \xdb\t";
cin >>n_gallons;
cout<<"The equivalent in cubic feet : \xdb\t"<<n_gallons / g_per_f<<endl;
cout<<"\n !Press c to continue or any key to exit."<<endl<<endl;
}while(getch()=='c');
}
Code:
/**2. Write a program that generates the following table:
1990 135
1991 7290
1992 11300
1993 16200
Use a single cout statement for all output.*/
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"-------------------------------------------------------------------------------\n\n";
int i, i_arr[4]={135,7290,11300,16200};
do{
for(i=1990;i<1994;i++) cout<<i<<setw(7)<<i_arr[i-1990]<<endl;
cout<<"\n !Press c to continue or any key to exit."<<endl<<endl;
}while(getch()=='c');
}
Code:
/**3. Write a program that generates the following output:
10
20
19
Use an integer constant for the 10, an arithmetic assignment operator to generate the 20, and a
decrement operator to generate the 19. */
#include<iostream.h>
#include<conio.h>
#define ten 10
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"-------------------------------------------------------------------------------\n\n";
//int ten = 10; //### use this line in the place of "define"
//int second, third;
//second = 2*ten; third = second-1;
//cout<<ten<<endl<<second<<endl<<third<<endl;
do{
cout<<ten<<endl<<2*ten<<endl<<2*ten-1<<endl;
cout<<"\n !Press c to continue or any key to exit."<<endl<<endl;
}while(getch()=='c');
}
Code:
/*4. Write a program that displays your favorite poem. Use an appropriate escape sequence for the
line breaks. If you don’t have a favorite poem, you can borrow this one by Ogden Nash:
Candy is dandy,
But liquor is quicker.
*/
#include<iostream.h>
#include<conio.h>
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"-------------------------------------------------------------------------------\n\n";
do{
cout<<"\tLa Ilah Ila Allah\n\tMohamed Rasoul Allah"<<endl;
cout<<"\n !Press c to continue or any key to exit."<<endl<<endl;
}while(getch()=='c');
}
Code:
/*5. A library function, islower(), takes a single character (a letter) as an argument and returns a
nonzero integer if the letter is lowercase, or zero if it is uppercase. This function requires the header
file CTYPE.H. Write a program that allows the user to enter a letter, and then displays either zero or
nonzero, depending on whether a lowercase or uppercase letter was entered. (See the SQRT
program for clues.)*/
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"-------------------------------------------------------------------------------\n\n";
do{
cout<<"Enter a letter : \xdb\t"<<endl;
cout<<islower(getch())<<"\nthis value must be zero if you entred an uppercase letter and nonzero case else."<<endl;
cout<<"\n !Press c to continue or any key to exit."<<endl<<endl;
}while(getch()=='c');
}
Code:
/*6. On a certain day the British pound was equivalent to $1.487 U.S., the French franc was $0.172,
the German deutschemark was $0.584, and the Japanese yen was $0.00955. Write a program that
allows the user to enter an amount in dollars, and then displays this value converted to these four
other monetary units.*/
#include<iostream.h>
#include<conio.h>
#define pound 1.487
#define franc 0.172
#define deutschemark 0.584
#define yen 0.00955
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<"-------------------------------------------------------------------------------\n\n";
int dollars;
do{
cout<<"Enter the U.S. amout : \xdb\t";
cin >>dollars;
cout<<endl;
cout<<"British pound =\t" << dollars / pound <<endl;
cout<<"French franc =\t" << dollars / franc <<endl;
cout<<"German deutschemark =\t" << dollars / deutschemark <<endl;
cout<<"Japanese yen =\t" << dollars / yen <<endl;
//cout<<"\nAnother operation ? (y/n) : "; //use this line to continue using the programme.
cout<<"\n !Press c to continue or any key to exit."<<endl<<endl;
}while(getch()=='c');
}
No comments:
Post a Comment