include <iostream>
include <ctime>
using namespace std;
//① 菜單 的技巧
/*void meun_information( )
{
int n;
cout<<"1--存款"<<endl;
cout<<"2--取款"<<endl;
cout<<"3--轉賬"<<endl; //語句塊的分割
cout<<"4--查詢"<<endl;
cout<<"5--退出"<<endl;
cout<<"please enter a number you want to enter !"<<endl;
cin>>n;
switch(n)
{
case 1: cout<<"1 --存款"<<endl; break;
case 2: cout<<"2 --取款"<<endl; break;
case 3: cout<<"3 --轉賬"<<endl; break;
case 4: cout<<"4 --查詢"<<endl; break;
case 5: cout<<"5 --退出"<<endl; break;
default: cout<<"輸入錯誤,重新輸入"<<endl; meun_information( );break; //輸入錯誤時,返回菜單。。
}
}
/
//②簡單for 循環
/
void for_loop()
{
int i,j;
cout<<"please input you want to input the number of times!"<<endl;
cin>>j;
for(i=1;i<=j;i++)
cout<<i<<"次"<<endl;
}
/
//③ 機器睡眠設置
/int time_sleep(int n)
{
while(n>0)
{
long t = time(NULL);
t += 1;
while(t>time(NULL));
cout<<t/CLOCKS_PER_SEC<<endl;
n--;
}
}/
/運算符的概念
①改變變量的值 ++后 --后 =
②結果和變量一致 前++ 前--
控制語句
①條件if ---else
②分支 switch(int、字符、bool、enum)
③循環 for while
④跳轉 break、goto loop continue語句和break語句的區別是:
continue語句只結束本次循環,而不終止整個循環的執行。而break語句則是結束整個循環過程,不再判斷執行循環的條件是否成立。
/
//四:金字塔 設計
/int pyramid(int n)
{
int i;
int j;
int row=n;
int space;
for(i=1; i<=row; i++)
{
space = row - i;
for(;space>=0;space--)
{ //空格語句塊
cout<<' ';
}
for(j=1;j<=i;j++)
{
cout<<j; //打印前半部分
}
for(j=i-1;j>0;j--)
{
cout<<j; //打印 后半部分 唉,這部分想了好久。居然沒想到。。
}
cout<<""<<endl; //打印換行部分
}
}
/
//五:邏輯短路的理解 判斷閏年
/
int judge_leep_year(int n)
{
int i;
int j=1;
for(i=0;i<=n;i++)
{
// if(i%400==0||(i%4==0&&i%100!=0)) //邏輯短路問題 ||前面為1 &&前面為0 發生邏輯短路
if((i%4==0&&i%100!=0)||i%400==0) //如果一年能被4整除并且不能被100整除,或者能被400整除,那么這一年就是閏年。
{
cout<<i<<endl;j++;}
}
cout<<j<<endl;
}
*/
//六:函數重載
/*
//函數重載 :相同的函數名,不同的參數表 eg int f_add(a);和 int f_add(int a,int b) 個數 類型 (double 和int、float)
int f_add(int x)
{
return x;
}
int f_add(double x)
{
return x;
}
int f_add(int x,int y)
{
return x+y;
}
double f_add(int x, double y)
{
return (double)x+y;
}
*/
// 階乘
/*
double factorial(int x){
if(x<0)
cout<<"不存在負數的階乘"<<endl;
else if(x==1||x==0)
return 1;
else
return xfactorial(x-1);//一定要分清是xfactorial(x-1),而不是factorial(x)*factorial(x-1)
}
*/
main()
{
// int n;
// meun_information(); //菜單語句塊
// for_loop(); //循環語句塊
// cout<<"please input you want to sleep time (s)"<<endl;
// cout<<"please input how many years leep year "<<endl;
//cin>>n;
// time_sleep(n);
// pyramid(n); //金字塔函數
// judge_leep_year(n); //判斷閏年
/*
int x,y;
double z;
cout<<f_add(3)<<endl;
cout<<f_add(3.00999)<<endl;
cout<<f_add(2,3.000099)<<endl;
cout<<f_add(3,5)<<endl;
*/
/*
int n;
cin>>n;
cout<<n<<"! = "<<factorial(n)<<endl;
*/
return 0 ;
}
include<iostream>
using namespace std;
/*int return_number() //int 類型能返回值到調用函數的位置,void不能返回參數
{
int n;
cin>>n;
return n;
}
*/
/*
簡單的四則運算
int f_add(int x,int y)
{
int c;
c = x+y;
return c; //只要是int 定義的函數最后一致以return 結尾。。
}
int f_reduce(int x,int y)
{
int c;
c = x - y;
return c;
}
int f_mul(int x,int y)
{
int c ;
c = x*y;
return c;
}
int f_division(int x,int y)
{
int c;
c = x%y;
return c;
}
// 簡單的四則運算 利用語句塊。
int main()
{
// cout<<return_number()<<endl;
int a,b,c;
do{
cout<<"please enter number cloose you want to function! "<<endl;
cout<<"1--add_function"<<endl;
cout<<"2--reduce_function"<<endl;
cout<<"3--mul_function"<<endl;
cout<<"4--diviction"<<endl;
cin>>c;
}while(c>4&&c<1);
cout<<"please input two number! "<<endl;
cin>>a>>b;
switch(c){
case 1:cout<<a<<"+"<<b<<"="<<f_add(a,b)<<endl;;break;
case 2:cout<<a<<"-"<<b<<"="<<f_reduce(a,b)<<endl;;break;
case 3:cout<<a<<"*"<<b<<"="<<f_mul(a,b)<<endl;;break;
case 4:cout<<a<<"/"<<b<<"="<<f_division(a,b)<<endl;;break;
default:cout<<"等待更新其他功能!"<<endl;break;
}
} */
//函數重載 :相同的函數名,不同的參數表 eg int f_add(a);和 int f_add(int a,int b) 個數 類型 (double 和int、float)