運(yùn)行: 需要連接數(shù)據(jù)庫(kù),本人用的SQL2008R2,使用其更改版本導(dǎo)入就行 com.operate.Main 包 Main.java 為主函數(shù)接口 PS:如果beautyeye_lnf.jar包報(bào)錯(cuò),導(dǎo)入其lib目錄下的對(duì)應(yīng)包即可 登錄: 管理員-- 帳號(hào);密碼 :admin;1 或者 1;1 學(xué) 生-- 帳號(hào);密碼 :01001;01001 數(shù)據(jù)庫(kù): com.means.sql 包 SqlKey.java 提供了參數(shù) com.means.sql 包 SqlCmd.java 提供了當(dāng)前數(shù)據(jù)庫(kù)的查詢語(yǔ)句(不推薦更改,數(shù)據(jù)庫(kù)已提供) 還需改進(jìn): 課程表數(shù)據(jù)跟學(xué)生成績(jī)數(shù)據(jù)太少, 課程表的管理沒有寫,偷個(gè)懶 如果需要可以對(duì)照 StuManage 跟 StuUpdate 倆個(gè)類來(lái)寫,直接復(fù)制就可以了。 PS: 還有問(wèn)題可以聯(lián)系 Q.2095204800
標(biāo)簽: 管理系統(tǒng)
上傳時(shí)間: 2017-06-27
上傳用戶:aaass
A simple example of audio signal processing on TMS320VC5416 USB DSK board. Main source is contained in tone.c file, memory configuration - tonecfg.cmd. Folder docs/ contains useful docmentation on board, its components and libraries. The example's configuration is based on example "tone" from Code Composer Studio's 3.1 example for 5416 DSK.
標(biāo)簽: DSK-example 5416 TMS 320 VC
上傳時(shí)間: 2017-09-29
上傳用戶:wang1104014663
/****************temic*********t5557***********************************/ #include <at892051.h> #include <string.h> #include <intrins.h> #include <stdio.h> #define uchar unsigned char #define uint unsigned int #define ulong unsigned long //STC12C2051AD的SFR定義 sfr WDT_CONTR = 0xe1;//stc2051的看門狗?????? /**********全局常量************/ //寫卡的命令 #define write_command0 0//寫密碼 #define write_command1 1//寫配置字 #define write_command2 2//密碼寫數(shù)據(jù) #define write_command3 3//喚醒 #define write_command4 4//停止命令 #define TRUE 1 #define FALSE 0 #define OK 0 #define ERROR 255 //讀卡的時(shí)間參數(shù)us #define ts_min 250//270*11.0592/12=249//取近似的整數(shù) #define ts_max 304//330*11.0592/12=304 #define t1_min 73//90*11.0592/12=83:-10調(diào)整 #define t1_max 156//180*11.0592/12=166 #define t2_min 184//210*11.0592/12=194 #define t2_max 267//300*11.0592/12=276 //***********不采用中斷處理:采用查詢的方法讀卡時(shí)關(guān)所有中斷****************/ sbit p_U2270B_Standby = P3^5;//p_U2270B_Standby PIN=13 sbit p_U2270B_CFE = P3^3;//p_U2270B_CFE PIN=6 sbit p_U2270B_OutPut = P3^7;//p_U2270B_OutPut PIN=2 sbit wtd_sck = P1^7;//SPI總線 sbit wtd_si = P1^3; sbit wtd_so = P1^2; sbit iic_data = P1^2;//lcd IIC sbit iic_clk = P1^7; sbit led_light = P1^6;//測(cè)試綠燈 sbit led_light1 = P1^5;//測(cè)試紅燈 sbit led_light_ok = P1^1;//讀卡成功標(biāo)志 sbit fengmingqi = P1^5; /***********全局變量************************************/ uchar data Nkey_a[4] = {0xA0, 0xA1, 0xA2, 0xA3};//初始密碼 //uchar idata card_snr[4]; //配置字 uchar data bankdata[28] = {1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7}; //存儲(chǔ)卡上用戶數(shù)據(jù)(1-7)7*4=28 uchar data cominceptbuff[6] = {1,2,3,4,5,6};//串口接收數(shù)組ram uchar command; //第一個(gè)命令 uchar command1;// //uint temp; uchar j,i; uchar myaddr = 8; //uchar ywqz_count,time_count; //ywqz jishu: uchar bdata DATA; sbit BIT0 = DATA^0; sbit BIT1 = DATA^1; sbit BIT2 = DATA^2; sbit BIT3 = DATA^3; sbit BIT4 = DATA^4; sbit BIT5 = DATA^5; sbit BIT6 = DATA^6; sbit BIT7 = DATA^7; uchar bdata DATA1; sbit BIT10 = DATA1^0; sbit BIT11 = DATA1^1; sbit BIT12 = DATA1^2; sbit BIT13 = DATA1^3; sbit BIT14 = DATA1^4; sbit BIT15 = DATA1^5; sbit BIT16 = DATA1^6; sbit BIT17 = DATA1^7; bit i_CurrentLevel;//i_CurrentLevel BIT 00H(Saves current level of OutPut pin of U2270B) bit timer1_end; bit read_ok = 0; //緩存定時(shí)值,因用同一個(gè)定時(shí)器 union HLint { uint W; struct { uchar H;uchar L; } B; };//union HLint idata a union HLint data a; //緩存定時(shí)值,因用同一個(gè)定時(shí)器 union HLint0 { uint W; struct { uchar H; uchar L; } B; };//union HLint idata a union HLint0 data b; /**********************函數(shù)原型*****************/ //讀寫操作 void f_readcard(void);//全部讀出1~7 AOR喚醒 void f_writecard(uchar x);//根據(jù)命令寫不同的內(nèi)容和操作 void f_clearpassword(void);//清除密碼 void f_changepassword(void);//修改密碼 //功能子函數(shù) void write_password(uchar data *data p);//寫初始密碼或數(shù)據(jù) void write_block(uchar x,uchar data *data p);//不能用通用指針 void write_bit(bit x);//寫位 /*子函數(shù)區(qū)*****************************************************/ void delay_2(uint x) //延時(shí),時(shí)間x*10us@12mhz,最小20us@12mhz { x--; x--; while(x) { _nop_(); _nop_(); x--; } _nop_();//WDT_CONTR=0X3C;不能頻繁的復(fù)位 _nop_(); } ///////////////////////////////////////////////////////////////////// void initial(void) { SCON = 0x50; //串口方式1,允許接收 //SCON =0x50; //01010000B:10位異步收發(fā),波特率可變,SM2=0不用接收到有效停止位才RI=1, //REN=1允許接收 TMOD = 0x21; //定時(shí)器1 定時(shí)方式2(8位),定時(shí)器0 定時(shí)方式1(16位) TCON = 0x40; //設(shè)定時(shí)器1 允許開始計(jì)時(shí)(IT1=1) TH1 = 0xfD; //FB 18.432MHz 9600 波特率 TL1 = 0xfD; //fd 11.0592 9600 IE = 0X90; //EA=ES=1 TR1 = 1; //啟動(dòng)定時(shí)器 WDT_CONTR = 0x3c;//使能看門狗 p_U2270B_Standby = 0;//單電源 PCON = 0x00; IP = 0x10;//uart you xian XXXPS PT1 PX1 PT0 PX0 led_light1 = 1; led_light = 0; p_U2270B_OutPut = 1; } /************************************************/ void f_readcard()//讀卡 { EA = 0;//全關(guān),防止影響跳變的定時(shí)器計(jì)時(shí) WDT_CONTR = 0X3C;//喂狗 p_U2270B_CFE = 1;// delay_2(232); //>2.5ms /* // aor 用喚醒功能來(lái)防碰撞 p_U2270B_CFE = 0; delay_2(18);//start gap>150us write_bit(1);//10=操作碼讀0頁(yè) write_bit(0); write_password(&bankdata[24]);//密碼block7 p_U2270B_CFE =1 ;// delay_2(516);//編程及確認(rèn)時(shí)間5.6ms */ WDT_CONTR = 0X3C;//喂狗 led_light = 0; b.W = 0; while(!(read_ok == 1)) { //while(p_U2270B_OutPut);//等一個(gè)穩(wěn)定的低電平?超時(shí)判斷? while(!p_U2270B_OutPut);//等待上升沿的到來(lái)同步信號(hào)檢測(cè)1 TR0 = 1; //deng xia jiang while(p_U2270B_OutPut);//等待下降沿 TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1;//定時(shí)器晚啟動(dòng)10個(gè)周期 //同步頭 if((324 < a.W) && (a.W < 353)) ;//檢測(cè)同步信號(hào)1 else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } //等待上升沿 while(!p_U2270B_OutPut); TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1;//b.N1<<=8; if(a.B.L < 195);//0.5p else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } //讀0~7塊的數(shù)據(jù) for(j = 0;j < 28;j++) { //uchar i; for(i = 0;i < 16;i++)//8個(gè)位 { //等待下降沿的到來(lái) while(p_U2270B_OutPut); TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1; if(t2_max < a.W/*)&&(a.W < t2_max)*/)//1P { b.W >>= 2;//先左移再賦值 b.B.L += 0xc0; i++; } else if(t1_min < a.B.L/*)&&(a.B.L < t1_max)*/)//0.5p { b.W >>= 1; b.B.L += 0x80; } else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } i++; while(!p_U2270B_OutPut);//上升 TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1; if(t2_min < a.W/*)&&(a.W < t2_max)*/)//1P { b.W >>= 2; i++; } else if(t1_min < a.B.L/*a.W)&&(a.B.L < t1_max)*/)//0.5P //else if(!(a.W==0)) { b.W >>= 1; //temp+=0x00; //led_light1=0;led_light=1;delay_2(40000); } else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } i++; } //取出奇位 DATA = b.B.L; BIT13 = BIT7; BIT12 = BIT5; BIT11 = BIT3; BIT10 = BIT1; DATA = b.B.H; BIT17 = BIT7; BIT16 = BIT5; BIT15 = BIT3; BIT14 = BIT1; bankdata[j] = DATA1; } read_ok = 1;//讀卡完成了 read_error: _nop_(); } } /***************************************************/ void f_writecard(uchar x)//寫卡 { p_U2270B_CFE = 1; delay_2(232); //>2.5ms //psw=0 standard write if (x == write_command0)//寫密碼:初始化密碼 { uchar i; uchar data *data p; p = cominceptbuff; p_U2270B_CFE = 0; delay_2(31);//start gap>330us write_bit(1);//寫操作碼1:10 write_bit(0);//寫操作碼0 write_bit(0);//寫鎖定位0 for(i = 0;i < 35;i++) { write_bit(1);//寫數(shù)據(jù)位1 } p_U2270B_CFE = 1; led_light1 = 0; led_light = 1; delay_2(40000);//測(cè)試使用 //write_block(cominceptbuff[4],p); p_U2270B_CFE = 1; bankdata[20] = cominceptbuff[0];//密碼存入 bankdata[21] = cominceptbuff[1]; bankdata[22] = cominceptbuff[2]; bankdata[23] = cominceptbuff[3]; } else if (x == write_command1)//配置卡參數(shù):初始化 { uchar data *data p; p = cominceptbuff; write_bit(1);//寫操作碼1:10 write_bit(0);//寫操作碼0 write_bit(0);//寫鎖定位0 write_block(cominceptbuff[4],p); p_U2270B_CFE= 1; } //psw=1 pssword mode else if(x == write_command2) //密碼寫數(shù)據(jù) { uchar data*data p; p = &bankdata[24]; write_bit(1);//寫操作碼1:10 write_bit(0);//寫操作碼0 write_password(p);//發(fā)口令 write_bit(0);//寫鎖定位0 p = cominceptbuff; write_block(cominceptbuff[4],p);//寫數(shù)據(jù) } else if(x == write_command3)//aor //喚醒 { //cominceptbuff[1]操作碼10 X xxxxxB uchar data *data p; p = cominceptbuff; write_bit(1);//10 write_bit(0); write_password(p);//密碼 p_U2270B_CFE = 1;//此時(shí)數(shù)據(jù)不停的循環(huán)傳出 } else //停止操作碼 { write_bit(1);//11 write_bit(1); p_U2270B_CFE = 1; } p_U2270B_CFE = 1; delay_2(560);//5.6ms } /************************************/ void f_clearpassword()//清除密碼 { uchar data *data p; uchar i,x; p = &bankdata[24];//原密碼 p_U2270B_CFE = 0; delay_2(18);//start gap>150us //操作碼10:10xxxxxxB write_bit(1); write_bit(0); for(x = 0;x < 4;x++)//發(fā)原密碼 { DATA = *(p++); for(i = 0;i < 8;i++) { write_bit(BIT0); DATA >>= 1; } } write_bit(0);//鎖定位0:0 p = &cominceptbuff[0]; write_block(0x00,p);//寫新配置參數(shù):pwd=0 //密碼無(wú)效:即清除密碼 DATA = 0x00;//停止操作碼00000000B for(i = 0;i < 2;i++) { write_bit(BIT7); DATA <<= 1; } p_U2270B_CFE = 1; delay_2(560);//5.6ms } /*********************************/ void f_changepassword()//修改密碼 { uchar data *data p; uchar i,x,addr; addr = 0x07;//block7 p = &Nkey_a[0];//原密碼 DATA = 0x80;//操作碼10:10xxxxxxB for(i = 0;i < 2;i++) { write_bit(BIT7); DATA <<= 1; } for(x = 0;x < 4;x++)//發(fā)原密碼 { DATA = *(p++); for(i = 0;i < 8;i++) { write_bit(BIT7); DATA >>= 1; } } write_bit(0);//鎖定位0:0 p = &cominceptbuff[0]; write_block(0x07,p);//寫新密碼 p_U2270B_CFE = 1; bankdata[24] = cominceptbuff[0];//密碼存入 bankdata[25] = cominceptbuff[1]; bankdata[26] = cominceptbuff[2]; bankdata[27] = cominceptbuff[3]; DATA = 0x00;//停止操作碼00000000B for(i = 0;i < 2;i++) { write_bit(BIT7); DATA <<= 1; } p_U2270B_CFE = 1; delay_2(560);//5.6ms } /***************************子函數(shù)***********************************/ void write_bit(bit x)//寫一位 { if(x) { p_U2270B_CFE = 1; delay_2(32);//448*11.0592/120=42延時(shí)448us p_U2270B_CFE = 0; delay_2(28);//280*11.0592/120=26寫1 } else { p_U2270B_CFE = 1; delay_2(92);//192*11.0592/120=18 p_U2270B_CFE = 0; delay_2(28);//280*11.0592/120=26寫0 } } /*******************寫一個(gè)block*******************/ void write_block(uchar addr,uchar data *data p) { uchar i,j; for(i = 0;i < 4;i++)//block0數(shù)據(jù) { DATA = *(p++); for(j = 0;j < 8;j++) { write_bit(BIT0); DATA >>= 1; } } DATA = addr <<= 5;//0地址 for(i = 0;i < 3;i++) { write_bit(BIT7); DATA <<= 1; } } /*************************************************/ void write_password(uchar data *data p) { uchar i,j; for(i = 0;i < 4;i++)// { DATA = *(p++); for(j = 0;j < 8;j++) { write_bit(BIT0); DATA >>= 1; } } } /*************************************************/ void Main() { initial(); TI = RI = 0; ES = 1; EA = 1; delay_2(28); //f_readcard(); while(1) { f_readcard(); //讀卡 f_writecard(command1); //寫卡 f_clearpassword(); //清除密碼 f_changepassword(); //修改密碼 } }
標(biāo)簽: 12345
上傳時(shí)間: 2017-10-20
上傳用戶:my_lcs
在本課中,我們要用一個(gè)按鍵來(lái)實(shí)現(xiàn)跑馬燈的 10 級(jí)調(diào)速。這又會(huì)涉及到鍵的去抖的問(wèn) 題。 本課的試驗(yàn)結(jié)果是,每按一次按鍵,跑馬速度就降低一級(jí),共 10 級(jí)。 這里我們又增加了一個(gè)變量 speedlever,來(lái)保存當(dāng)前的速度檔次。 在按鍵里的處理中,多了當(dāng)前檔次的延時(shí)值的設(shè)置。 請(qǐng)看程序: ―――――――――――――――― #define uchar unsigned char //定義一下方便使用 #define uint unsigned int #define ulong unsigned long #include <reg52.h> //包括一個(gè) 52 標(biāo)準(zhǔn)內(nèi)核的頭文件 sbit P10 = P1^0; //頭文件中沒有定義的 IO 就要自己來(lái)定義了 sbit P11 = P1^1; sbit P12 = P1^2; sbit P13 = P1^3; sbit K1= P3^2; bit ldelay=0; //長(zhǎng)定時(shí)溢出標(biāo)記,預(yù)置是 0 uchar speed=10; //設(shè)置一個(gè)變量保存默認(rèn)的跑馬燈的移動(dòng)速度 uchar speedlever=0; //保存當(dāng)前的速度檔次 char code dx516[3] _at_ 0x003b;//這是為了仿真設(shè)置的 //一個(gè)按鍵控制的 10 級(jí)變速跑馬燈試驗(yàn) void Main(void) // 主程序 { uchar code ledp[4]={0xfe,0xfd,0xfb,0xf7};//預(yù)定的寫入 P1 的值 uchar ledi; //用來(lái)指示顯示順序 uint n; RCAP2H =0x10; //賦 T2 的預(yù)置值 0x1000,溢出 30 次就是 1 秒鐘 RCAP2L =0x00; TR2=1; //啟動(dòng)定時(shí)器 ET2=1; //打開定時(shí)器 2 中斷 EA=1; //打開總中斷 while(1) //主程序循環(huán) { if(ldelay) //發(fā)現(xiàn)有時(shí)間溢出標(biāo)記,進(jìn)入處理 { ldelay=0; //清除標(biāo)記 P1=ledp[ledi]; //讀出一個(gè)值送到 P1 口 ledi++; //指向下一個(gè) if(ledi==4) { ledi=0; //到了最后一個(gè)燈就換到第一個(gè) } } if(!K1) //如果讀到 K1 為 0 { for(n=0;n<1000;n++); //等待按鍵穩(wěn)定 while(!K1); //等待按鍵松開 for(n=0;n<1000;n++); //等待按鍵穩(wěn)定松開 speedlever++; if(speedlever==10)speedlever=0; speed=speedlever*3; //檔次和延時(shí)之間的預(yù)算法則,也可以用查表方法,做出 不規(guī)則的法則 } } } //定時(shí)器 2 中斷 timer2() interrupt 5 { static uchar t; TF2=0; t++; if((t==speed)||(t>30)) //比較一個(gè)變化的數(shù)值,以實(shí)現(xiàn)變化的時(shí)間溢出,同時(shí)限制了最慢速 度為 1 秒 { t=0; ldelay=1;//每次長(zhǎng)時(shí)間的溢出,就置一個(gè)標(biāo)記,以便主程序處理 } } ―――――――――――――――――――――― 請(qǐng)打開 lesson11 目錄的工程,編譯,運(yùn)行,看結(jié)果: 按 K1,速度則降低一次,總共 10 個(gè)檔次。
上傳時(shí)間: 2017-11-06
上傳用戶:szcyclone
LED 一般是恒流操作的,如何改變 LED 的亮度呢?答案就是 PWM 控制。在一定的 頻率的方波中,調(diào)整高電平和低電平的占空比,即可實(shí)現(xiàn)。比如我們用低電平點(diǎn)亮一個(gè) LED 燈,我們假設(shè)把一個(gè)頻率周期分為 10 個(gè)時(shí)間等份,如果方波中的高低電平占空比是 9:1, 這是就是一個(gè)比較暗的亮度,如果方波中高低電平占空比是 10:0,這時(shí),全部是高電平, 燈是滅的。如果占空比是 5:5,就是一個(gè)中間亮度,如果高低比是 1:9,是一個(gè)比較亮的 亮度,如果高低是 0:10,這時(shí)全部是低電平,就是最亮的。 實(shí)際上應(yīng)用中,電視屏幕墻中的幾十百萬(wàn) LED 象素都是這樣控制的,而且每一個(gè)象素 都有紅綠藍(lán) 3 個(gè) LED,每個(gè) LED 可以變化的亮度是幾百到幾萬(wàn)或者更多的級(jí)別,以實(shí)現(xiàn)真 彩色的顯示。還有在您的手機(jī)中,背光燈的亮度如果是可以變化的,也應(yīng)該是這種工作方式。 目前的城市彩燈也有很多都使用了 LED,需要控制亮度是也是 PWM 控制。 下面來(lái)分析我們的例程,在這個(gè)例程中,我們將定時(shí)器 2 溢出定為 1/1200 秒。每 10 次脈沖輸出一個(gè) 120HZ 頻率。這每 10 次脈沖再用來(lái)控制高低電平的 10 個(gè)比值。這樣,在 每個(gè) 1/120 秒的方波周期中,我們都可以改變方波的輸出占空比,從而控制 LED 燈的 10 個(gè) 級(jí)別的亮度。 為什么輸出方波的頻率要 120HZ 這么高?因?yàn)槿绻l率太低,人眼就會(huì)看到閃爍感 覺。一般起碼要在 60HZ 以上才感覺好點(diǎn),120HZ 就基本上看不到閃爍,只能看到亮度的變 化了。 下面請(qǐng)看程序,程序中有比較多的注釋: ――――――――――――――――――――――― #define uchar unsigned char //定義一下方便使用 #define uint unsigned int #define ulong unsigned long #include <reg52.h> //包括一個(gè) 52 標(biāo)準(zhǔn)內(nèi)核的頭文件 sbit P10 = P1^0; //要控制的 LED 燈 sbit K1= P3^2; //按鍵 K1 uchar scale;//用于保存占空比的輸出 0 的時(shí)間份額,總共 10 份 char code dx516[3] _at_ 0x003b;//這是為了仿真設(shè)置的 //模擬 PWM 輸出控制燈的 10 個(gè)亮度級(jí)別 void Main(void) // 主程序 { uint n; RCAP2H =0xF3; //賦 T2 的預(yù)置值,溢出 1 次是 1/1200 秒鐘 RCAP2L =0x98; TR2=1; //啟動(dòng)定時(shí)器 ET2=1; //打開定時(shí)器 2 中斷 EA=1; //打開總中斷 while(1) //程序循環(huán) { ;//主程序在這里就不斷自循環(huán),實(shí)際應(yīng)用中,這里是做主要工作 for(n=0;n<50000;n++); //每過(guò)一會(huì)兒就自動(dòng)加一個(gè)檔次的亮度 scale++; if(scale==10)scale=0; } } //1/1200 秒定時(shí)器 2 中斷 timer2() interrupt 5 { static uchar tt; //tt 用來(lái)保存當(dāng)前時(shí)間在一秒中的比例位置 TF2=0; tt++; if(tt==10) //每 1/120 秒整開始輸出低電平 { tt=0; if(scale!=0) //這里加這一句是為了消除滅燈狀態(tài)產(chǎn)生的鬼影 P10=0; } if(scale==tt) //按照當(dāng)前占空比切換輸出高電平 P10=1; } ―――――――――――――――――― 在主程序中,每延時(shí)一段時(shí)間,就自動(dòng)換一個(gè)占空比,以使亮度自動(dòng)變化,方便觀察。 編譯,運(yùn)行,看結(jié)果。 可以看到,LED 的亮度以每種亮度 1 秒左右不斷變化,共有 10 個(gè)級(jí)別。
上傳時(shí)間: 2017-11-06
上傳用戶:szcyclone
題目:古典問(wèn)題:有一對(duì)兔子,從出生后第3個(gè)月起每個(gè)月都生一對(duì)兔子,小兔子長(zhǎng)到第三個(gè)月后每個(gè)月又生一對(duì)兔子,假如兔子都不死,問(wèn)每個(gè)月的兔子總數(shù)為多少? //這是一個(gè)菲波拉契數(shù)列問(wèn)題 public class lianxi01 { public static void Main(String[] args) { System.out.println("第1個(gè)月的兔子對(duì)數(shù): 1"); System.out.println("第2個(gè)月的兔子對(duì)數(shù): 1"); int f1 = 1, f2 = 1, f, M=24; for(int i=3; i<=M; i++) { f = f2; f2 = f1 + f2; f1 = f; System.out.println("第" + i +"個(gè)月的兔子對(duì)數(shù): "+f2); } } } 【程序2】 題目:判斷101-200之間有多少個(gè)素?cái)?shù),并輸出所有素?cái)?shù)。 程序分析:判斷素?cái)?shù)的方法:用一個(gè)數(shù)分別去除2到sqrt(這個(gè)數(shù)),如果能被整除, 則表明此數(shù)不是素?cái)?shù),反之是素?cái)?shù)。 public class lianxi02 { public static void Main(String[] args) { int count = 0; for(int i=101; i<200; i+=2) { boolean b = false; for(int j=2; j<=Math.sqrt(i); j++) { if(i % j == 0) { b = false; break; } else { b = true; } } if(b == true) {count ++;System.out.println(i );} } System.out.println( "素?cái)?shù)個(gè)數(shù)是: " + count); } } 【程序3】 題目:打印出所有的 "水仙花數(shù) ",所謂 "水仙花數(shù) "是指一個(gè)三位數(shù),其各位數(shù)字立方和等于該數(shù)本身。例如:153是一個(gè) "水仙花數(shù) ",因?yàn)?53=1的三次方+5的三次方+3的三次方。 public class lianxi03 { public static void Main(String[] args) { int b1, b2, b3;
上傳時(shí)間: 2017-12-24
上傳用戶:Ariza
程序顯示: 一年內(nèi)總降雨量、平均每月的降雨量、降雨量最大的月份和最小的月份。 #include<iostream> using namespace std; #include<stdlib.h> int Main() .. .. .. cout<<"降雨量最小的月份是:"<<minyue<<"月 "<<"降雨量為:"<<min<<endl; }
標(biāo)簽: float 編寫 程序 用戶 數(shù)組 存儲(chǔ) 輸入
上傳時(shí)間: 2018-03-27
上傳用戶:shayusha
#include <stdio.h> #include <stdlib.h> ///鏈?zhǔn)綏?nbsp; typedef struct node { int data; struct node *next; }Node,*Linklist; Linklist Createlist() { Linklist p; Linklist h; int data1; scanf("%d",&data1); if(data1 != 0) { h = (Node *)malloc(sizeof(Node)); h->data = data1; h->next = NULL; } else if(data1 == 0) return NULL; scanf("%d",&data1); while(data1 != 0) { p = (Node *)malloc(sizeof(Node)); p -> data = data1; p -> next = h; h = p; scanf("%d",&data1); } return h; } void Outputlist(Node *head) { Linklist p; p = head; while(p != NULL ) { printf("%d ",p->data); p = p->next; } printf("\n"); } void Freelist(Node *head) { Node *p; Node *q = NULL; p = head; while(p != NULL) { q = p; p = p->next; free(q); } } int Main() { Node *head; head = Createlist(); Outputlist(head); Freelist(head); return 0; } 2.順序棧 [cpp] view plain copy #include <iostream> #include <stdio.h> #include <stdlib.h> ///順序棧 #define MaxSize 100 using namespace std; typedef
標(biāo)簽: 數(shù)據(jù)結(jié)構(gòu) 實(shí)驗(yàn)
上傳時(shí)間: 2018-05-09
上傳用戶:123456..
#include <iostream> #include <stdio.head> #include <stdlib.head> #include <string.head> #define ElemType int #define max 100 using namespace std; typedef struct node1 { ElemType data; struct node1 *next; }Node1,*LinkList;//鏈棧 typedef struct { ElemType *base; int top; }SqStack;//順序棧 typedef struct node2 { ElemType data; struct node2 *next; }Node2,*LinkQueue; typedef struct node22 { LinkQueue front; LinkQueue rear; }*LinkList;//鏈隊(duì)列 typedef struct { ElemType *base; int front,rear; }SqQueue;//順序隊(duì)列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 //1.采用鏈?zhǔn)酱鎯?chǔ)實(shí)現(xiàn)棧的初始化、入棧、出棧操作。 LinkList CreateStack()//創(chuàng)建棧 { LinkList top; top=NULL; return top; } bool StackEmpty(LinkList s)//判斷棧是否為空,0代表空 { if(s==NULL) return 0; else return 1; } LinkList Pushead(LinkList s,int x)//入棧 { LinkList q,top=s; q=(LinkList)malloc(sizeof(Node1)); q->data=x; q->next=top; top=q; return top; } LinkList Pop(LinkList s,int &e)//出棧 { if(!StackEmpty(s)) { printf("棧為空。"); } else { e=s->data; LinkList p=s; s=s->next; free(p); } return s; } void DisplayStack(LinkList s)//遍歷輸出棧中元素 { if(!StackEmpty(s)) printf("棧為空。"); else { wheadile(s!=NULL) { cout<<s->data<<" "; s=s->next; } cout<<endl; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 //2.采用順序存儲(chǔ)實(shí)現(xiàn)棧的初始化、入棧、出棧操作。 int StackEmpty(int t)//判斷棧S是否為空 { SqStack.top=t; if (SqStack.top==0) return 0; else return 1; } int InitStack() { SqStack.top=0; return SqStack.top; } int pushead(int t,int e) { SqStack.top=t; SqStack.base[++SqStack.top]=e; return SqStack.top; } int pop(int t,int *e)//出棧 { SqStack.top=t; if(!StackEmpty(SqStack.top)) { printf("棧為空."); return SqStack.top; } *e=SqStack.base[s.top]; SqStack.top--; return SqStack.top; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //3.采用鏈?zhǔn)酱鎯?chǔ)實(shí)現(xiàn)隊(duì)列的初始化、入隊(duì)、出隊(duì)操作。 LinkList InitQueue()//創(chuàng)建 { LinkList head; head->rear=(LinkQueue)malloc(sizeof(Node)); head->front=head->rear; head->front->next=NULL; return head; } void deleteEle(LinkList head,int &e)//出隊(duì) { LinkQueue p; p=head->front->next; e=p->data; head->front->next=p->next; if(head->rear==p) head->rear=head->front; free(p); } void EnQueue(LinkList head,int e)//入隊(duì) { LinkQueue p=(LinkQueue)malloc(sizeof(Node)); p->data=e; p->next=NULL; head->rear->next=p; head->rear=p; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 //4.采用順序存儲(chǔ)實(shí)現(xiàn)循環(huán)隊(duì)列的初始化、入隊(duì)、出隊(duì)操作。 bool InitQueue(SqQueue &head)//創(chuàng)建隊(duì)列 { head.data=(int *)malloc(sizeof(int)); head.front=head.rear=0; return 1; } bool EnQueue(SqQueue &head,int e)//入隊(duì) { if((head.rear+1)%MAXQSIZE==head.front) { printf("隊(duì)列已滿\n"); return 0; } head.data[head.rear]=e; head.rear=(head.rear+1)%MAXQSIZE; return 1; } int QueueLengthead(SqQueue &head)//返回隊(duì)列長(zhǎng)度 { return (head.rear-head.front+MAXQSIZE)%MAXQSIZE; } bool deleteEle(SqQueue &head,int &e)//出隊(duì) { if(head.front==head.rear) { cout<<"隊(duì)列為空!"<<endl; return 0; } e=head.data[head.front]; head.front=(head.front+1)%MAXQSIZE; return 1; } int gethead(SqQueue head)//得到隊(duì)列頭元素 { return head.data[head.front]; } int QueueEmpty(SqQueue head)//判斷隊(duì)列是否為空 { if (head.front==head.rear) return 1; else return 0; } void travelQueue(SqQueue head)//遍歷輸出 { wheadile(head.front!=head.rear) { printf("%d ",head.data[head.front]); head.front=(head.front+1)%MAXQSIZE; } cout<<endl; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 //5.在主函數(shù)中設(shè)計(jì)一個(gè)簡(jiǎn)單的菜單,分別測(cè)試上述算法。 int Main() { LinkList top=CreateStack(); int x; wheadile(scanf("%d",&x)!=-1) { top=Pushead(top,x); } int e; wheadile(StackEmpty(top)) { top=Pop(top,e); printf("%d ",e); }//以上是鏈棧的測(cè)試 int top=InitStack(); int x; wheadile(cin>>x) top=pushead(top,x); int e; wheadile(StackEmpty(top)) { top=pop(top,&e); printf("%d ",e); }//以上是順序棧的測(cè)試 LinkList Q; Q=InitQueue(); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q,x); } int e; wheadile(Q) { deleteEle(Q,e); printf("%d ",e); }//以上是鏈隊(duì)列的測(cè)試 SqQueue Q1; InitQueue(Q1); int x; wheadile(scanf("%d",&x)!=-1) { EnQueue(Q1,x); } int e; wheadile(QueueEmpty(Q1)) { deleteEle(Q1,e); printf("%d ",e); } return 0; }
標(biāo)簽: 數(shù)據(jù)結(jié)構(gòu) 實(shí)驗(yàn)
上傳時(shí)間: 2018-05-09
上傳用戶:123456..
#include "iostream" using namespace std; class Matrix { private: double** A; //矩陣A double *b; //向量b public: int size; Matrix(int ); ~Matrix(); friend double* Dooli(Matrix& ); void Input(); void Disp(); }; Matrix::Matrix(int x) { size=x; //為向量b分配空間并初始化為0 b=new double [x]; for(int j=0;j<x;j++) b[j]=0; //為向量A分配空間并初始化為0 A=new double* [x]; for(int i=0;i<x;i++) A[i]=new double [x]; for(int m=0;m<x;m++) for(int n=0;n<x;n++) A[m][n]=0; } Matrix::~Matrix() { cout<<"正在析構(gòu)中~~~~"<<endl; delete b; for(int i=0;i<size;i++) delete A[i]; delete A; } void Matrix::Disp() { for(int i=0;i<size;i++) { for(int j=0;j<size;j++) cout<<A[i][j]<<" "; cout<<endl; } } void Matrix::Input() { cout<<"請(qǐng)輸入A:"<<endl; for(int i=0;i<size;i++) for(int j=0;j<size;j++){ cout<<"第"<<i+1<<"行"<<"第"<<j+1<<"列:"<<endl; cin>>A[i][j]; } cout<<"請(qǐng)輸入b:"<<endl; for(int j=0;j<size;j++){ cout<<"第"<<j+1<<"個(gè):"<<endl; cin>>b[j]; } } double* Dooli(Matrix& A) { double *Xn=new double [A.size]; Matrix L(A.size),U(A.size); //分別求得U,L的第一行與第一列 for(int i=0;i<A.size;i++) U.A[0][i]=A.A[0][i]; for(int j=1;j<A.size;j++) L.A[j][0]=A.A[j][0]/U.A[0][0]; //分別求得U,L的第r行,第r列 double temp1=0,temp2=0; for(int r=1;r<A.size;r++){ //U for(int i=r;i<A.size;i++){ for(int k=0;k<r-1;k++) temp1=temp1+L.A[r][k]*U.A[k][i]; U.A[r][i]=A.A[r][i]-temp1; } //L for(int i=r+1;i<A.size;i++){ for(int k=0;k<r-1;k++) temp2=temp2+L.A[i][k]*U.A[k][r]; L.A[i][r]=(A.A[i][r]-temp2)/U.A[r][r]; } } cout<<"計(jì)算U得:"<<endl; U.Disp(); cout<<"計(jì)算L的:"<<endl; L.Disp(); double *Y=new double [A.size]; Y[0]=A.b[0]; for(int i=1;i<A.size;i++ ){ double temp3=0; for(int k=0;k<i-1;k++) temp3=temp3+L.A[i][k]*Y[k]; Y[i]=A.b[i]-temp3; } Xn[A.size-1]=Y[A.size-1]/U.A[A.size-1][A.size-1]; for(int i=A.size-1;i>=0;i--){ double temp4=0; for(int k=i+1;k<A.size;k++) temp4=temp4+U.A[i][k]*Xn[k]; Xn[i]=(Y[i]-temp4)/U.A[i][i]; } return Xn; } int Main() { Matrix B(4); B.Input(); double *X; X=Dooli(B); cout<<"~~~~解得:"<<endl; for(int i=0;i<B.size;i++) cout<<"X["<<i<<"]:"<<X[i]<<" "; cout<<endl<<"呵呵呵呵呵"; return 0; }
標(biāo)簽: 道理特分解法
上傳時(shí)間: 2018-05-20
上傳用戶:Aa123456789
蟲蟲下載站版權(quán)所有 京ICP備2021023401號(hào)-1