Concept : จงเขียนผังงาน เพื่อทำการคำนวนค่าจดรถตามอัตรานี้้ คือ 1 ชั่่วโมงละ 20 บาท ชั.......
Ex:********************************************************************
Input :
Enter hour : 1
Enter minute : 10
Output :
Parking fee =20 baht
****************************************************************
Code:
//===============================================================//
#include<iostream> // Parking fee : under 1h : 20 after 10,upper than 15min = 1hour
using namespace std;
int main(){
int h,m,c=0;
loop:
cout<<"\nEnter hour(<=72) : ";cin>>h;
cout<<"\nEnter minute : ";cin>>m;
if(h<0||h>72||m<0||m>59){
cout<<"\nEnter again!\n\n";
goto loop;
}
if(h==0){
if(m>15)
c+=20;
else
c+=0;
}
if(h>0){
if(m>15)
c+=10;
c+=20;
while(h>1){
c+=10;
h--;
}
}
cout<<"\n\nParking fee = "<<c<<" baht";
cout<<"\n\nDo it again or not y/n : ";
char o;
cin>>o;
if(o=='y')
{c=0;goto loop;}
return 0;
}
//===============================================================//
2.Histogram :
Concept :
Ex:********************************************************************
Input :
Enter n : 5
Enter 5 number :
3
5
1
0
6
Output :
Histogram :
3 ***
5 *****
1 *
0
6 ******
****************************************************************
Code:
//===============================================================//
#include<iostream> // Histogram
using namespace std;
int main(){
int n , X[10];
loop1:
cout<<"\nEnter n : ";cin>>n;
if(n<=0||n>10){
cout<<"\nEnter n again ! (0<n<=10) ";
goto loop1;
}
cout<<"\nEnter "<<n<<" number : \n";
for(int i=0;i<n;i++){
loop2:
cin>>X[i];
if(X[i]<0||X[i]>25){
cout<<"\nEnter that number again (0<=X<=25)\n\n";
goto loop2;
}
}
cout<<"\n\nHistogram : \n";
for(int i=0;i<n;i++){
cout<<X[i]<<"\t";
for(int j=0;j<X[i];j++)
cout<<"*";
cout<<endl;
}
return 0;
}
//===============================================================//
3.Reverse and multiply :
Concept :
Ex:********************************************************************
Input :
321
Output :
246
****************************************************************
Code:
//===============================================================//
#include<iostream> // Reverse and multiply
using namespace std;
int main(){
int n,m,reverse = 0; // n:number
loop1:
cout<<"\nEnter number : ";cin>>n;
if(n<=0||n>9999){
cout<<"\nPlease Enter number again !(0<number<=9999)\n";
goto loop1;
}
while(n>0){
m = n%10;
n/=10;
reverse = reverse*10+m;
}
cout<<"\nResult : "<<reverse*2;
return 0;
}
//===============================================================//
Concept :
Ex:********************************************************************
Input :
Enter first word : khmers
Enter second word : merskh
Enter second word : merskh
Output :
Yes
****************************************************************
Code:
//===============================================================//
#include<iostream>#include<string.h>
using namespace std;
int main(){
/*set 1st word , 2nd word ,
location of order , length of word */
char w1[10],w2[10];
int loca=0,len=0;
char charator;
string answer="Yes";
w1:
cout<<"Enter first word : ";
cin>>w1;
/*Length of both must <=10 charator*/
if(strlen(w1)>10){
cout<<w1<<" is so long\nTry that again!(<=10charator)\n";
goto w1;
}
w2:
cout<<"\nEnter second word : ";
cin>>w2;
if(strlen(w2)>10){
cout<<w2<<" is so long\nTry that again!(<=10charator)\n";
goto w2;
}
/*condition of 2word's length equaltion*/
if(strlen(w1)!=strlen(w2)){
cout<<"\nThat 2words have no the same length ! try them again!\n";
goto w1;
}
/*Copy length both word to len*/
len=strlen(w1);
/*order charactor of both word to compare , */
for(int i=0;i<len;i++){
charator=w1[i];
loca=i;
for(int j=i+1;j<strlen(w1);j++){
if(charator>w1[j]){
charator=w1[j];
loca=j;
}
}
/*Swape charator when order charator*/
char temp;
temp=w1[i];
w1[i]=w1[loca];
w1[loca]=temp;
}
for(int i=0;i<len;i++){
charator=w2[i];
loca=i;
for(int j=i+1;j<strlen(w2);j++){
if(charator>w2[j]){
charator=w2[j];
loca=j;
}
}
char temp;
temp=w2[i];
w2[i]=w2[loca];
w2[loca]=temp;
}
/*compare both word that was ordered
and condition if unequal even one charactor
give a word No to answer*/
for(int i=0;i<len;i++){
if(w1[i]!=w2[i])
answer="No";
}
/*Display answer !!*/
cout<<endl<<answer<<endl;
return 0;
}
//===============================================================//
No comments:
Post a Comment