简单程序源代码

合集下载

简易计算器程序源代码

简易计算器程序源代码

简易计算器程序源代码下面是一个简易计算器程序的源代码,它可以执行基本的四则运算:```python#定义加法函数def add(x, y):return x + y#定义减法函数def subtract(x, y):return x - y#定义乘法函数def multiply(x, y):return x * y#定义除法函数def divide(x, y):if y == 0:return "除数不能为0"else:return x / y#显示菜单print("选择操作:")print("1. 相加")print("2. 相减")print("3. 相乘")print("4. 相除")#获取用户输入choice = input("输入你的选择(1/2/3/4): ")#获取用户输入的两个数字num1 = float(input("输入第一个数字: "))num2 = float(input("输入第二个数字: "))#根据用户选择执行相应操作if choice == '1':print(num1, "+", num2, "=", add(num1, num2))elif choice == '2':print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '3':print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '4':print(num1, "/", num2, "=", divide(num1, num2))else:print("请输入有效的选择")```运行这个程序,你将看到一个简易的计算器菜单。

python程序源代码

python程序源代码

python程序源代码(实用版)目录1.Python 程序源代码概述2.Python 程序源代码的特点3.Python 程序源代码的发展4.Python 程序源代码的应用领域5.Python 程序源代码的未来发展趋势正文一、Python 程序源代码概述Python 程序源代码是一种采用 Python 语言编写的计算机程序代码。

Python 语言作为一门广泛应用于多个领域的编程语言,其源代码具有简洁、易读、高效等特点,深受广大开发者喜爱。

二、Python 程序源代码的特点1.语法简洁:Python 语言的语法简洁明了,使得编写程序变得轻松愉快。

2.易读性强:Python 源代码结构清晰,可读性强,易于维护。

3.高效开发:Python 源代码具有丰富的库和框架支持,可以快速开发出高质量的应用程序。

4.跨平台:Python 源代码支持多种操作系统,如 Windows、Linux、Mac OS 等,具有较高的可移植性。

三、Python 程序源代码的发展Python 语言自 1991 年诞生以来,经历了多次版本更新,其源代码也在不断完善和丰富。

如今,Python 已经成为全球最受欢迎的编程语言之一,其源代码在多个领域都有着广泛的应用。

四、Python 程序源代码的应用领域Python 源代码在众多领域都有广泛应用,如:1.Web 开发:Python 源代码在 Web 开发领域有着丰富的框架支持,如 Django、Flask 等,可以快速构建高质量的 Web 应用。

2.数据分析:Python 源代码在数据分析领域有着强大的支持,如Pandas、NumPy 等库,可以方便地处理和分析海量数据。

3.人工智能:Python 源代码在人工智能领域有着广泛的应用,如TensorFlow、PyTorch 等深度学习框架,可以助力开发者快速开发智能应用。

4.网络编程:Python 源代码在网络编程方面有着丰富的库支持,如Requests、asyncio 等,可以方便地处理网络编程相关任务。

C#程序源代码_辛苦整理

C#程序源代码_辛苦整理
if(each [j]>=each [j+1])
{
temp=each [j];
each [j]=each [j+1];
{
if ((sieve >> i & 0x01) != 0)
Console.Write("{0,3}", p);
p += 2;
}
Console.WriteLine();
sum+=t;
}
Console .WriteLine ("\nPI={0,10:f8}",sum *6);
Console .Read ();
}
}
}
抓图结果:
{
each [i++]=num%10;
num=num/10;
}
for(i=0;i<3;i++)
for(j=0;j<3-i;j++)
C#程序设计
一、实验名称:C#实验
二、实验目的:通过上机实际操作将平时课堂所学具体实现,通过该实验来检查自己的学习成功,并且发现平时学习中没有注意到的问题并解决之,从而加深对该门课程的以及C#语言的了解。
三、实验步骤:
实验一:C#编程环境
实验目的:
1. 熟悉掌握C#开发环境的安装与配置
num = max -min ;
Console .WriteLine ("{0}-{1}={2}",max,min,num);
}
Console .Read();
}
相关的主要代码:

简易水电费管理系统源程序代码

简易水电费管理系统源程序代码

简易水电费管理系统源程序代码法一:#include<stdio.h>#include<string.h>#include<stdlib.h>struct member{char no[100];char name[20];char password[20];float wfee;float efee;}memb;void newadd(int n){ int t,i;fseek(fp,0,SEEK_END);printf(">>新添人数:");scanf("%d",&t);for(i=0;i<t;i++){ printf("新添第%d个成员:");scanf("%s %s %s %f %f",memb.no,,memb.password,memb.wfee,memb.efee); fwrite(&memb,sizeof(struct member),1,fp);}}void look(int n){ char a[100];printf(">>输入卡号:");scanf("%s",a);int i=0;rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)||memb.no==a) break;i++;}if(!feof(fp)){ printf(">>卡号:");printf("%s\n",memb.no);printf(">>姓名:");printf("%s\n",");printf(">>水费:");printf("%f\n",memb.wfee);printf(">>电费:");printf("%f\n",memb.efee);}elseprintf(">>查无此人\n");};void delete(int n){ char c[100];printf(">>删除的卡号:");scanf("%s," c);if((fp1=fopen("temp.bin","wb"))==NULL){printf(">>不能建立临时文件,无法删除\n");}rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)) break;if(memb.no!=c)fwrite(&memb,sizeof(struct member),1,fp1);}fclose(fp1);fclose(fp);remove("member.bin");rename("temp.bin","member.bin");fp=fopen("member.bin","rb++");};main(){ char a[100]; char b[20];FILE *fp;printf("欢迎进入水电费管理系统\n")int i=0,sel=1;if((fp=fopen("member.bin","wb++"))==NULL){ printf(">>不能建立member.bin文件\n");return(0);}while(sel!=0){ printf("| 1 | 2 | 3 | 4 |\n"); printf("| ------------------------------------------------------------ |\n"); printf("|新添成员|查找个人信息|删除成员|退出|\n); fseek(fp,0,SEEK_END);scanf("%d",&sel);switch(sel){ case 1:newadd(sel); break;clscr(); exit(0);case 2:printf("请输入您的卡号:");printf("%s",a);printf("请输入您的密码:");puts(b);while(strcmp(a,memb.no)==0&&strcmp(b,memb.password)==0)look(sel);printf("您的输入有误\n"); break;clscr();exit(0);case 3:delete(sel); break;clscr();exit(0);}法二:#include<stdio.h>#include<string.h>#include<stdlib.h>#include<windows.h>#include<conio.h>struct member{char no[100];char name[20];char password[20];float wfee;float efee;}memb;void newadd(int n){ int t,i;FILE *fp;fp=fopen("e:\\member.bin","a");fseek(fp,0,SEEK_END);printf(">>新添人数:");scanf("%d",&t);for(i=0;i<t;i++){ printf("新添第%d个成员:",i+1);scanf("%s %s %s %f %f",memb.no,,memb.password,&memb.wfee,&memb.efee); fwrite(&memb,sizeof(struct member),1,fp);}fclose(fp);}void look(int n){ char a[100],b[20]; FILE *fp;int i;fp=fopen("e:\\member.bin","rb");if(fp==NULL) printf("****");printf(">>输入卡号:");scanf("%s",a);i=0;rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)||strcmp(memb.no,a)==0) break;i++;}if(!feof(fp)){ printf(">>卡号:");printf("%s\n",memb.no);printf(">>姓名:");printf("%s\n",);printf(">>水费:");printf("%f\n",memb.wfee);printf(">>电费:");printf("%f\n",memb.efee);}elseprintf(">>查无此人\n");getch();fclose(fp);}void dele(int n){ char c[100];FILE *fp,*fp1;fp=fopen("e:\\member.bin","rb");printf(">>删除的卡号:");scanf("%s" ,c);if((fp1=fopen("temp.bin","wb"))==NULL){printf(">>不能建立临时文件,无法删除\n");}rewind(fp);while(1){ fread(&memb,sizeof(struct member),1,fp);if(feof(fp)) break;if(strcmp(memb.no,c)!=0)fwrite(&memb,sizeof(struct member),1,fp1);} fclose(fp1);fclose(fp);remove("member.bin");rename("temp.bin","member.bin");fp=fopen("member.bin","rb+");}main(){ char a[100]; char b[20];int i=0,sel=1;FILE *fp;printf("欢迎进入水电费管理系统\n");if((fp=fopen("e:\\member.bin","wb"))==NULL){ printf(">>不能建立member.bin文件\n");return(0);}while(sel!=0){ printf("| 1 | 2 | 3 | 4 |\n"); printf("| ------------------------------------------------------------ |\n"); printf("|新添成员|查找个人信息|删除成员|退出|\n"); fseek(fp,0,SEEK_END);scanf("%d",&sel);printf("sel=%d\n",sel);switch(sel){ case 1:newadd(sel);system("cls"); break;case 2:look(sel);system("cls"); break;case 3:dele(sel);system("cls");break;}}}。

经典C语言源代码

经典C语言源代码

经典C语言源代码1、(1)某年某月某日是星期几#include<stdio.h>intmain(){intyear,month,day;{if(month==1||month==2)//判断month是否为1或2{ year--;month+=12;}intc=year/100;inty=year-c*100;intweek=(c/4)-2*c+(y+y/4)+(13*(month+1)/5)+day-1;while(week<0){week+=7;}week%=7;switch(week){}}return0;}1、(2)某年某月某日是第几天(一维数组)voidmain(){inti,flag,year,month,day,dayth;intmonth_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};请输入年/月/日:dayth=day;flag=(year%400==0)||(year%4==0&&year%100!=0);if(flag)month_day[2]=29;for(i=1;i<month;i++)dayth=dayth+month_day[i];是第%4天}2、30个数中找最小的数及其位置#defineSIZE30voidmain(){inti;floatdata[SIZE];intmin;请输入%d个浮点数:for(i=0;i<SIZE;i++){data[i]=rand()%30+1;、}min=0;for(i=1;i<SIZE;i++){if(data[i]<data[min])min=i;最小值是%5.2f,位置是}3、30个数从小到大排序(1)#defineSIZE30voidmain(){inti,j;floatdata[SIZE],temp;intmin;请输入%d个整型数:for(i=0;i<SIZE;i++){}for(i=0;i<SIZE;i++){min=i;for(j=i+1;j<SIZE;j++)if(data[j]<data[min])temp=data[min];data[min]=data[i];data[i]=temp;}排序后的结果是:for(i=0;i<SIZE;i++)min=j;}(2)模块化程序(数组名作为函数参数)#defineSIZE5voidaccept_array(floata[],intsize);voidsort(floata[],intsize); voidshow_array(floata[],intsize);voidmain(){floatscore[SIZE];accept_array(score,SIZE);排序前:show_array(score,SIZE);sort(score,SIZE);排序后:show_array(score,SIZE);}voidaccept_array(floata[],intsize){inti;请输入%d个分数:for(i=0;i<size;i++)}voidshow_array(floata[],intsize){inti;for(i=0;i<size;i++)}voidsort(floata[],intsize){inti,min,j;floattemp;for(i=0;i<SIZE;i++){min=i;for(j=i+1;j<SIZE;j++)if(a[j]<a[min])min=j;}temp=a[min]; a[min]=a[i]; a[i]=temp;}}4、(1)指针加减:#defineSIZE10voidmain(){inta[SIZE]={1,2,3,4,5,6,7,8,9,10};int*pa,i;pa=&a[0];//pa=a;for(i=0;i<SIZE;i++){pa++;(2)指针比较:#defineSIZE10voidmain(){inta[SIZE]={1,2,3,4,5,6,7,8,9,10};int*pa,i;int*qa;pa=qa=&a[0];请输入%d整型数:for(;pa<qa+SIZE;pa++)for(pa--;qa<=pa;pa--)}5、两字符串相连:voidstr_cat(charstr1[],charstr2[]);voidmain(){inti,j;charstr1[160];charstr2[80];请输入第一个字符串:gets(str1);请输入第二个字符串:gets(str2);str_cat(str1,str2);puts(str1);}voidstr_cat(charstr1[],charstr2[]){ inti,j;i=0;i++;j=0;str1[i]=str2[j];i++;j++;}}6、二维数组(a,b转置)voidmain(){inti,j,b[2][3];inta[3][2]={{1,2},{3,4},{5,6}};for(i=0;i<2;i++){for(j=0;j<3;j++)b[i][j]=a[j][i];}for(i=0;i<3;i++){for(j=0;j<2;j++)}for(i=0;i<2;i++){for(j=0;j<3;j++)}7、输入一个二维数组并输出(指针)voidmain(){intx[2][3];inti,j;for(i=0;i<2;i++)for(j=0;j<3;j++)putchar('');for(i=0;i<2;i++){for(j=0;j<3;j++)putchar('');}}8、冒泡法排序一个数组#definesize10voidmaopao(inta[]);voidmain(){inta[10];inti;请输入10个整数:for(i=0;i<10;i++)maopao(a);}voidmaopao(inta[]){inti,j,temp;for(i=0;i<9;i++){//进行9轮排序for(j=0;j<9-i;j++)//每轮进行9-i次交换{if(a[j]>a[j+1]){temp=a[j];a[j]=a[j+1];//大的沉底,小的上浮a[j+1]=temp;排序结果:for(i=0;i<10;i++)}}9、两数组A,B,要求A<B,如A :4,7,9B :1,3,5,8,9变换后A :1,3, 5B :4,7,8,9,9#include<stdio.h>voidReArranger(int*A,int*B,intm,intn)//A和B是各有m个和n个整数的非降序数组,本算法将B数组元素逐个插入到A中,使A中各元素均不大于B中各元素,且两数组仍保持非降序排列。

简单易懂的C语言源代码(供初学者使用)

简单易懂的C语言源代码(供初学者使用)

#include<stdio.h>main(){float pi=3.14159265,r;printf("enter radius:\n");scanf("%f",&r);printf("r=%.2f,c=%.2f,area=%.2f\n",r,2*pi*r,pi*r*r);system("pause");}#include<stdio.h>main(){int m,n,x,y;printf("inputm,n:\n");scanf("%d%d",&m,&n);if (n%2==1){printf("error!! n bu shi ji shu!\n",n);return;}/*n在这里不能是奇数*/x=(4*m-n)/2;y=(n-2*m)/2;if((x>=0)&&(y>=0))printf("x=%d,y=%d\n",x,y); elseprintf("shu ru cuo wu!\n");getch();}#include<stdio.h>#include<math.h>#include<stdlib.h>main(){float a,b,C;printf("enter 3number(a,b,C):\n"); scanf("%.2f %.2f %.2f",&a,&b,&C); s=0.5*a*b*sinC;printf("s=%.2f\n",s);system("pause");}#include<stdio.h>main(){int ds,nl,yf;char c;printf("shu ru ds;\n");scanf("%d",&ds);if (ds<14||ds>1184){printf("input error!press any end...\n"); scanf("%c",&c);exit(0);}/*输入的数字必须是-14~1184之间*/nl=(ds+115)%100;yf=(ds+115)/100;printf("nl=%d,yf=%d\n",nl,yf);system("pause");}#include<stdio.h>#include<string.h>main(){char s1[100],s2[100],s3[100],s4[100]; printf("input a string:\n");gets(s1);strcpy(s1,s2);strcat(s1,"--------------");strcpy(s3,strcat(s1,"--------------"));strcat(strcpy(s3,strcat(s1,"--------------")),s2);strcpy(s4,strcat(strcpy(s3,strcat(s1,"--------------")),s2)); puts(s4);system("pasue");getch();}#include<stdio.h>#include<math.h>main(){float x1,x2,a,b,c;printf("input 3 number(a,b,c):\n");scanf("%f%f%f",&a,&b,&c);x1=(-b+sqrt(b*b-4*a*c))/(2*a);x2=(-b-sqrt(b*b-4*a*c))/(2*a);printf("x1=%f,X2=%f\n",x1,x2);system("pause");getch();}#include<stdio.h>main(){int a,b,c,t;printf("input 3 number:\n");scanf("%d%d%d",&a,&b,&c);if(a>b){t=a;a=b,b=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}printf("1:%d,2:%d,3:%d\n",a,b,c);system("pause");}#include<stdio.h>#include<stdlib.h>#include<conio.h>main(){float pi=3.14159265,r;textbackground(YELLOW);/* 设置背景色为黄色,注意颜色应该大写,可更改 */ textcolor(RED); /* 设置文件颜色为红色,可更改 */clrscr(); /* 清屏,使设置生效 */printf("enter radius:");scanf("%f",&r);if(r<0)printf("Enter Error!\n");elseprintf("r=%.2f,c=%.2f,area=%.2f\n",r,2*pi*r,pi*r*r); system("pause");/* 暂停,按任一键继续 */#include<stdio.h>#include<math.h>#include<conio.h>main(){float a,b,c,delt,x1,x2,p,q;textcolor(YELLOW);clrscr();printf("Input a b c:\n");scanf("%f%f%f",&a,&b,&c);if(a==0){printf("It's not a quadratic equation!\n");system("pause");return;}delt=b*b-4*a*c;if(delt>=0){x1=(-b+sqrt(delt))/(2*a);x2=(-b-sqrt(delt))/(2*a);printf("x1=%.3f x2=%.4f\n",x1,x2);}else{p=-b/(2*a);q=sqrt(-delt)/(2*a);printf("p=%.4fq=%.4f\n",p,q);}system("pause");getch();}}#include<stdio.h>main(){float pi=3.14159265,r;int k=0;while(k<=3){printf("enter radius:\n");scanf("%f",&r);printf("r=%.2f,c=%.2f,area=%.2f\n",r,2*pi*r,pi*r*r); printf("press any key to continue\npress esc to exit."); k++;}}#include<stdio.h>#include<stdlib.h>#include<time.h>#include<conio.h>main(){int a,b,c,oper;long limit,i=0;char char1;textcolor(GREEN);/*设置字体颜色为绿色*/clrscr(); /*清屏,是设置生效*/while(i<=3){printf("qing xuan ze jia huo jian(1or2,1:+,2:-\n"); scanf("%d",&oper);printf("Enter max (<10000):\n");scanf("%ld",&limit);srand((unsigned long)time(0));a=rand()*limit/RAND_MAX;b=rand()*limit/RAND_MAX;while((a<b)&&(oper==2)){a=rand()*limit/RAND_MAX;b=rand()*limit/RAND_MAX;}char1=(oper==2?'-':'+');printf("%d%c%d\n",a,char1,b);scanf("%d",&c);if((oper==2&&a-b==c)||(oper!=2&&a+b==c)) printf("OK!You are very clever!\n"); elseprintf("The result is not correct!\n"); i++;}getch();}#include<stdio.h>#include<conio.h>main(){int y,i=0;textcolor(YELLOW);/*天下事无难易之分只有做与不做之别*/ textbackground(GREEN);clrscr();/*清屏,是设置生效*/while(i<=3){printf("Input year:\n");scanf("%d",&y);if(y%4==0){if(y%100==0){if(y%400==0)printf("y shi run nian!\n"); elseprintf("y bu shi run nian !\n"); }elseprintf("y shi run nian!\n");}elseprintf("y bu shi run nian!");i++;}getche();}#include<stdio.h>#include<time.h>#include<string.h>main(){int xz,wday1,hour1;struct tm *timeptr;time_t secsnow;char s1[30],s2[30],s3[30];printf("input whom do you say to?:\n"); scanf("%d",&xz);if(xz==1)strcpy(s1,"mother");else if(xz==2)strcpy(s1,"father");elsestrcpy(s1,"");time(&secsnow);timeptr=localtime(&secsnow);wday1=timeptr->tm_wday;if(wday1==6)strcpy(s2,"Happy saturday!");else if(wday1==0)strcpy(s2,"Happy sunday");elsestrcpy(s2,"");hour1=timeptr->tm_hour;if(hour1>=4&&hour1<=10)strcpy(s3,"Good morning!");else if(hour1>=17&&hour1<=22)strcpy(s3,"Good afternoon!");elsestrcpy(s3,"Good evening!");printf("%s%s%s",s1,s2,s3);getch();}#include<stdio.h>#include<conio.h>main(){int day,year,month,i=0;textbackground(BROWN);clrscr();while(i<=3){printf("Input 2 number:\n");scanf("%d%d",&year,&month);switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12: day=31;break;case 4:case 6:case 11:day=30;break;case 2:day=28;if((year%4==0&&year%100!=0)||year%400==0)day=29;break;deflault:printf("Invalid month input!\n");return;}printf("There are%d days in %d.%d\n",day,year,month); i++;getch();}}。

计算机程序源代码

计算机程序源代码

计算机程序源代码// jisuanqiDlg: implementation file//#include "stdafx.h"#include "jisuanqi.h"#include "jisuanqiDlg.h"#include "math.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog{public:CAboutDlg();// Dialog Data//{{AFX_DATA(CAboutDlg)enum { IDD = IDD_ABOUTBOX };//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}void CAboutDlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)//{{AFX_MSG_MAP(CAboutDlg)// No message handlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CJisuanqiDlg dialogCJisuanqiDlg::CJisuanqiDlg(CWnd* pParent ): CDialog(CJisuanqiDlg::IDD, pParent){//{{AFX_DATA_INIT(CJisuanqiDlg)m_num = 0.0;//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CJisuanqiDlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CJisuanqiDlg)DDX_Text(pDX, IDC_EDIT1, m_num);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CJisuanqiDlg, CDialog)//{{AFX_MSG_MAP(CJisuanqiDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON3, OnButton3)ON_BN_CLICKED(IDC_BUTTON4, OnButton4)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)ON_BN_CLICKED(IDC_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTON14, OnButton0)ON_BN_CLICKED(IDC_BUTTON15, OnButtonPoint)ON_BN_CLICKED(IDC_BUTTON16, OnButtonEqual)ON_BN_CLICKED(IDC_BUTTON13, OnButtonChu)ON_BN_CLICKED(IDC_BUTTON12, OnButtonMul)ON_BN_CLICKED(IDC_BUTTON11, OnButtonSub)ON_BN_CLICKED(IDC_BUTTON10, OnButtonAdd)ON_BN_CLICKED(IDC_BUTTON17, OnButtondelet)ON_BN_CLICKED(IDC_BUTTON18, OnButtonclear)ON_BN_CLICKED(IDC_BUTTON19, OnButtonkaifang)ON_BN_CLICKED(IDC_BUTTON20, OnButtonziranduishu)ON_BN_CLICKED(IDC_BUTTON21, OnButtonchangyongduishu) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CJisuanqiDlg message handlersBOOL CJisuanqiDlg::OnInitDialog()//初始化变量{CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialogSetIcon(m_hIcon, TRUE); // Set big iconSetIcon(m_hIcon, FALSE); // Set small icon// TODO: Add extra initialization heret=true;j=true;i=10;p=0;q=0;m_num=0;m_lnum=0;return TRUE; // return TRUE unless you set the focus to a control }void CJisuanqiDlg::OnSysCommand(UINT nID, LPARAM lParam) {if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID, lParam);}}// If you add a minimize button to your dialog, you will need the code below// to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework.void CJisuanqiDlg::OnPaint(){if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icondc.DrawIcon(x, y, m_hIcon);}else{CDialog::OnPaint();}}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CJisuanqiDlg::OnQueryDragIcon(){return (HCURSOR) m_hIcon;}void CJisuanqiDlg::OnButton1(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+1;UpdateData(FALSE);}else{m_num=m_num+1.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton2(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+2;UpdateData(FALSE);}else{m_num=m_num+2.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton3(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+3;UpdateData(FALSE);}else{m_num=m_num+3.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton4(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+4;UpdateData(FALSE);}else{m_num=m_num+4.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton5(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+5;UpdateData(FALSE);}else{m_num=m_num+5.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton6(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+6;UpdateData(FALSE);}else{m_num=m_num+6.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton7(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+7;UpdateData(FALSE);}else{m_num=m_num+7.0/i;i*=10;UpdateData(FALSE);}void CJisuanqiDlg::OnButton8(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+8;UpdateData(FALSE);}else{m_num=m_num+8.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton9(){// TODO: Add your control notification handler code hereif(t){m_num=m_num*10+9;UpdateData(FALSE);}else{m_num=m_num+9.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButton0(){// TODO: Add your control notification handler code here //UpdateData();if(t){m_num=m_num*10+0;UpdateData(FALSE);}else{m_num=m_num+0.0/i;i*=10;UpdateData(FALSE);}}void CJisuanqiDlg::OnButtonPoint(){// TODO: Add your control notification handler code here int i=10;t=false;}void CJisuanqiDlg::OnButtonEqual(){// TODO: Add your control notification handler code hereswitch(r){case '+':{m_num=m_num+m_lnum;UpdateData(FALSE);break;}case '-':{m_num=m_snum-m_num;UpdateData(FALSE);break;}case '*':{m_num=m_mnum*m_num;UpdateData(FALSE);break;}case '/':{if(m_num==0){MessageBox("除数不能是0!");}else{m_num=m_cnum/m_num;UpdateData(FALSE);break;}}}t=true;}void CJisuanqiDlg::OnButtonMul(){// TODO: Add your control notification handler code here r='*';t=true;m_mnum=m_num;m_num=0;UpdateData(FALSE);void CJisuanqiDlg::OnButtonChu(){// TODO: Add your control notification handler code here r='/';t=true;i=10;m_cnum=m_num;m_num=0;UpdateData(FALSE);}void CJisuanqiDlg::OnButtonSub(){// TODO: Add your control notification handler code here r='-';i=10;t=true;if(j){m_snum=m_num;}else{p=0;adda[p]=m_num;p++;for(q=0;q<=p;q++){m_lnum=m_lnum+adda[q];q++;}m_num=m_lnum;UpdateData(FALSE);m_num=0;m_snum=m_lnum;}m_num=0;void CJisuanqiDlg::OnButtonAdd(){// TODO: Add your control notification handler code here r='+';t=true;j=false;i=10;p=0;adda[p]=m_num;p++;for(q=0;q<=p;q++){m_lnum=m_lnum+adda[q];q++;}m_num=m_lnum;UpdateData(FALSE);m_num=0;}void CJisuanqiDlg::OnButtondelet(){// TODO: Add your control notification handler code here int p;p=m_num/10;m_num=p;UpdateData(FALSE);}void CJisuanqiDlg::OnButtonclear(){// TODO: Add your control notification handler code here t=true;i=10;j=true;m_num=0;m_lnum=0;UpdateData(FALSE);}void CJisuanqiDlg::OnButtonkaifang(){// TODO: Add your control notification handler code herem_num=sqrt(m_num);UpdateData(FALSE);}void CJisuanqiDlg::OnButtonziranduishu(){// TODO: Add your control notification handler code here m_num=log(m_num);UpdateData(FALSE);}void CJisuanqiDlg::OnButtonchangyongduishu(){// TODO: Add your control notification handler code here m_num=log10(m_num);UpdateData(FALSE);}。

C#100例经典源代码

C#100例经典源代码
{
long int i,x, y, z;
for (i=1;i<100000;i++)
{ x=sqrt(i+100); /*x为加上100后开方后的结果*/
y=sqrt(i+268); /*y为再加上168后开方后的结果*/
i f (x*x== i +100&&y*y== i +268)/*如果一个数的平方根的平方等于该数,这说明此 数是完全平方数*/
bonus二bonus2+(i-200000) *;
else if(i<=600000)
bonus二bonus4+(i-400000)*;
else if(i<=1000000)
bonus二bonus6+(i-600000)*;
e I se
bonus二bonusl0+ (i T 000000)*; pr intf ("bonus=%d", bonus);
pr intf (H\n%ld\n,\ i);
}
)
【程序4】
题目:输入某年某月某日,判断这一天是这一年的第几天
1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即 本年的第几天,特殊
情况,闰年且输入月份大于3时需考虑多加一天。
2•程序源代码:
ma i n()
int day, month, year, sum, Ieap;
bonus4=bonus2+200000*;
bonus6=bonus4+200000*;
bonusl0=bonus6+400000*;
if (i<=100000)

C语言程序源代码

C语言程序源代码

C语言程序源代码C语言程序源代码#include <REGX51.H> // 51寄存器定义#include "intrins.h"#define control P1 //P1_0:A相,P1_1:B相,P1_2:C相,P1_3:D相#define discode P0 //显示代码控制端口#define uchar unsigned char //定义无符号型变量#define uint unsigned intsbit en_dm=P3^0; //显示代码锁存控制sbit en_wk=P3^1; //位控锁存控制uchar code corotation[4]= {0x03,0x06,0x0c,0x09};//电机正转uchar code rollback[4]={0x0c,0x06,0x03,0x09}; //电机反转uchar codetab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//显示字段uint code Levspeed[5]={500,400,300,200,100};//电机速度等级uchar Hscan,speedcount;//Hscan行扫描,speedcount 速度等级计数uint uu; //频率计数uint step,setstep; //step:电机步伐计数,setstep:手动设置电机步伐uint speed=500; //电机初始速度uchar count;uchar flag[5];uchar butcount; //按键次数//****************************************//flag[0] 正转标志//flag[1] 反转标志//flag[2] 加速标志//flag[3] 减速标志//flag[4] 设置标志//****************************************Delay1mS(unsigned int tt) //延时1ms “Delay1mS”延时子程序,用循环语句延时。

简单的迷宫小游戏C语言程序源代码

简单的迷宫小游戏C语言程序源代码

简单的迷宫小游戏C语言程序源代码#include <stdio.h>#include <conio.h>#include <windows.h> #include <time.h>#define Height 31 //迷宫的高度,必须为奇数 #define Width 25 //迷宫的宽度,必须为奇数 #define Wall 1#define Road 0#define Start 2#define End 3#define Esc 5#define Up 1#define Down 2#define Left 3#define Right 4int map[Height+2][Width+2]; void gotoxy(int x,int y) //移动坐标{COORD coord;coord.X=x;coord.Y=y;SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );}void hidden()//隐藏光标{HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci);cci.bVisible=0;//赋1为显示,赋0为隐藏SetConsoleCursorInfo(hOut,&cci);}void create(int x,int y) //随机生成迷宫 {int c[4][2]={0,1,1,0,0,-1,-1,0}; //四个方向 int i,j,t;//将方向打乱for(i=0;i<4;i++){j=rand()%4;t=c[i][0];c[i][0]=c[j][0];c[j][0]=t;t=c[i][1];c[i][1]=c[j][1];c[j][1]=t;}map[x][y]=Road;for(i=0;i<4;i++)if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall){map[x+c[i][0]][y+c[i][1]]=Road;create(x+2*c[i][0],y+2*c[i][1]);}}int get_key() //接收按键{char c;while(c=getch()) {if(c==27) return Esc; //Escif(c!=-32)continue; c=getch();if(c==72) return Up; //上if(c==80) return Down; //下if(c==75) return Left; //左if(c==77) return Right; //右}return 0;}void paint(int x,int y) //画迷宫 { gotoxy(2*y-2,x-1); switch(map[x][y]) { case Start:printf("入");break; //画入口case End:printf("出");break; //画出口case Wall:printf("※");break; //画墙case Road:printf(" ");break; //画路}}void game(){int x=2,y=1; //玩家当前位置,刚开始在入口处 int c; //用来接收按键while(1){gotoxy(2*y-2,x-1); printf("?"); //画出玩家当前位置if(map[x][y]==End) //判断是否到达出口{gotoxy(30,24); printf("到达终点,按任意键结束");getch();break;}c=get_key(); if(c==Esc){gotoxy(0,24); break;}switch(c){case Up: //向上走if(map[x-1][y]!=Wall){paint(x,y); x--;}break;case Down: //向下走if(map[x+1][y]!=Wall){paint(x,y); x++;}break;case Left: //向左走if(map[x][y-1]!=Wall){paint(x,y); y--;}break;case Right: //向右走if(map[x][y+1]!=Wall){paint(x,y); y++;}break;}}}int main(){int i,j;srand((unsigned)time(NULL)); //初始化随即种子 hidden(); //隐藏光标for(i=0;i<=Height+1;i++) for(j=0;j<=Width+1;j++)if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫 map[i][j]=Road;else map[i][j]=Wall;create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //从随机一个点开始生成迷宫,该点行列都为偶数for(i=0;i<=Height+1;i++) //边界处理 {map[i][0]=Wall;map[i][Width+1]=Wall; }for(j=0;j<=Width+1;j++) //边界处理{map[0][j]=Wall;map[Height+1][j]=Wall; }map[2][1]=Start; //给定入口map[Height-1][Width]=End; //给定出口 for(i=1;i<=Height;i++)for(j=1;j<=Width;j++) //画出迷宫paint(i,j);game(); //开始游戏getch();return 0;}。

c语言入门源代码

c语言入门源代码

c语言入门源代码以下是C语言入门的源代码,用于初学者学习和参考: 1. Hello World程序#include <stdio.h>int main() {printf('Hello World!');return 0;}2. 输入输出程序#include <stdio.h>int main() {int num;printf('请输入一个整数:');scanf('%d', &num);printf('您输入的整数是:%d', num);return 0;}3. 判断奇偶数#include <stdio.h>int main() {int num;printf('请输入一个整数:');scanf('%d', &num);if(num % 2 == 0) {printf('%d是偶数', num);} else {printf('%d是奇数', num);}return 0;}4. 计算两个数的和#include <stdio.h>int main() {int num1, num2, sum;printf('请输入两个整数,以空格隔开:');scanf('%d %d', &num1, &num2);sum = num1 + num2;printf('%d和%d的和是:%d', num1, num2, sum); return 0;}5. 计算n的阶乘#include <stdio.h>int main() {int n, i, factorial = 1;printf('请输入一个整数:');scanf('%d', &n);for(i = 1; i <= n; i++) {factorial *= i;}printf('%d的阶乘是:%d', n, factorial);return 0;}以上代码只是C语言入门的一部分,还有很多其他程序可以学习和练习。

编程代码大全

编程代码大全

编程代码大全在当今数字化的时代,编程成为了一项至关重要的技能。

无论是开发网站、创建应用程序,还是实现复杂的算法,编程代码都是实现这些目标的基石。

接下来,让我们一同探索各种各样的编程代码。

首先,我们来谈谈 Python 语言。

Python 以其简洁易懂的语法而闻名,对于初学者来说非常友好。

比如下面这段简单的代码,用于计算两个数的和:```pythonnum1 = 5num2 = 10result = num1 + num2print("两数之和为:", result)``````pythonmy_list = 1, 2, 3, 4, 5my_listappend(6)for num in my_list:print(num)``````javapublic class Rectangle {private int length;private int width;public Rectangle(int length, int width) {thislength = length;thiswidth = width;}public int getArea(){return length width;}public static void main(String args) {Rectangle rectangle = new Rectangle(5, 10);Systemoutprintln("矩形面积为: "+ rectanglegetArea());}}``````c++include <iostream>int factorial(int n) {if (n == 0 || n == 1) {return 1;} else {return n factorial(n 1);}}int main(){int num = 5;std::cout << num <<"的阶乘为: "<< factorial(num) <<std::endl;return 0;}```JavaScript 常用于网页开发,使网页具有动态交互性。

经典C源代码30例

经典C源代码30例

经典C源代码30例==============================================================【程序80】题目:海滩上有一堆桃子,五只猴子来分。

第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。

第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有多少个桃子?1.程序分析:2.程序源代码:main(){int i,m,j,k,count;for(i=4;i<10000;i+=4){ count=0;m=i;for(k=0;k<5;k++){j=i/4*5+1;i=j;if(j%4==0)count++;elsebreak;}i=m;if(count==4){printf("%d\n",count);break;}}}作者:zhlei81 2005-1-22 11:32 回复此发言--------------------------------------------------------------------------------16 回复:经典C源程序100例【程序81】题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。

求??代表的两位数,及809*??后的结果。

1.程序分析:2.程序源代码:output(long b,long i){ printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i);}main(){long int a,b,i;a=809;for(i=10;i<100;i++){b=i*a+1;if(b>=1000&&b<=10000&&8*i<100&&9*i>=100)output(b,i); }}==============================================================【程序82】题目:八进制转换为十进制1.程序分析:2.程序源代码:main(){ char *p,s[6];int n;p=s;gets(p);n=0;while(*(p)!='\0'){n=n*8+*p-'0';p++;}printf("%d",n);}============================================================== 【程序83】题目:求0—7所能组成的奇数个数。

C语言简单计算器程序源代码

C语言简单计算器程序源代码

C语言简单计算器程序源代码以下是一个简单的C语言计算器程序的源代码:```c#include <stdio.h>int maichar operator;double num1, num2;printf("请输入运算符:");scanf("%c", &operator);printf("请输入两个数字:");scanf("%lf %lf", &num1, &num2);switch (operator)case '+':printf("%.2lf + %.2lf = %.2lf", num1, num2, num1 + num2); break;case '-':printf("%.2lf - %.2lf = %.2lf", num1, num2, num1 - num2); break;case '*':printf("%.2lf * %.2lf = %.2lf", num1, num2, num1 * num2);break;case '/':if (num2 != 0)printf("%.2lf / %.2lf = %.2lf", num1, num2, num1 / num2);elseprintf("除数不能为0");break;default:printf("无效的运算符");}return 0;```这个程序首先提示用户输入一个运算符,然后再提示输入两个数字。

接下来,程序会根据输入的运算符执行相应的计算,并打印结果。

在计算除法时,程序会检查除数是否为0,如果为0,则打印错误信息。

请注意,这只是一个非常简单的计算器程序,没有考虑很多错误处理情况。

OPCClient浏览OPCServer的简单实例程序源代码

OPCClient浏览OPCServer的简单实例程序源代码

OPC Client浏览OPC Server的简单实例简单程序源代码://main.cpp//***************************************************************************** *******************//浏览本地OPC服务器//***************************************************************************** *******************#define _WIN32_DCOM // Needed in order to call CoInitializeEx()#include <iostream>#include <objbase.h>#include <comdef.h>#import "C:\WINNT\system32\OpcEnum.exe" no_namespace //根据OpcEnum.exe更改#include "opcda.h"#include "opcenum_i.c"//--------------------------------------------------------------------------------------------------------------//版本号----可以从规范中查到static const CLSID CA TID_OPCDAServer10 ={ 0x63d5f430, 0xcfe4, 0x11d1, { 0xb2, 0xc8, 0x0, 0x60, 0x8, 0x3b, 0xa1, 0xfb } };// {63D5F430-CFE4-11d1-B2C8-0060083BA1FB}static const CLSID CA TID_OPCDAServer20 ={ 0x63d5f432, 0xcfe4, 0x11d1, { 0xb2, 0xc8, 0x0, 0x60, 0x8, 0x3b, 0xa1, 0xfb } };// {63D5F432-CFE4-11d1-B2C8-0060083BA1FB}//[uuid(CC603642-66D7-48f1-B69A-B625E73652D7)] interface CATID_OPCDAServer30 //--------------------------------------------------------------------------------------------------------------void OPCServerList();int main(int argc, char* argv[]){HRESULT hr;int n_return = 0;try{// Initialize COMif(FAILED( hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) ))_com_issue_error(hr);}catch(_com_error e){std::cout << "ERROR(" << e.Error() << "): ";if( e.Description().length() > 0)std::cout << (TCHAR*)e.Description() << std::endl;elsestd::cout << e.ErrorMessage() << std::endl;n_return = 1;}OPCServerList();// Uninitialize COMCoUninitialize();return 0;}//使用CoCreateInstancevoid OPCServerList(){CLSID clsid;clsid = CLSID_OpcServerList; //在opcenum_i.c中定义IOPCServerList *gpOPC = NULL;DWORD clsctx;clsctx = CLSCTX_LOCAL_SERVER; //本地服务IID IIDOPCServerList=IID_IOPCServerList; //在opcenum_i.c中定义// 创建OPC服务器的浏览器对象-----HRESULT hr = CoCreateInstance(clsid, NULL, clsctx,IIDOPCServerList ,(void**)&gpOPC);// 查询OPC DA 2.0 组件目录接口指针CLSID catid;catid=CATID_OPCDAServer20; //= CA TID_OPCDAServer20; //OPC数据访问服务器2.0组件目录IOPCEnumGUID *pEnumGUID;hr = gpOPC->EnumClassesOfCategories( 1, &catid, 1, &catid, (IEnumGUID**)&pEnumGUID);if(S_OK!=hr)return;//获得支持OPC DA2.0数据服务器的CLSIDunsigned long c;while (S_OK == pEnumGUID->Next(1, &clsid, &c)){LPOLESTR pszProgID;LPOLESTR pszUserType;hr = gpOPC->GetClassDetails(&clsid, &pszProgID, &pszUserType);//打印OPC数据服务器的有关信息printf("ProgID = %ls, UserType = %ls\n", pszProgID, pszUserType);CoTaskMemFree(pszProgID);CoTaskMemFree(pszUserType);}//释放接口if(gpOPC)gpOPC->Release();}友情提示:范文可能无法思考和涵盖全面,供参考!最好找专业人士起草或审核后使用,感谢您的下载!。

程序源代码

程序源代码

程序源代码第一部分:相对算法代码(一)提零压缩生成流密文程序#include"iostream.h"#include"math.h"#include"stdlib.h"#include"time.h"#include"stdio.h"#include"fstream.h"#include"io.h"char getword(FILE *fp){ int *s;int i;s=&i;s[0]=getc(fp);s[1]=getc(fp);return (i);}//读入一个字int position(int a,int b)//求数组元素之间相对关系的函数:0表示与本身同性;而1反之{if((a&&b)||(!a&&!b))return 0;elsereturn 1;}int main(){ static unsigned char alawbyte[50000];//存放A率压缩后的样值static int data[50000];long offset=0;int i;int j=0;int k=0;long samples=0;static int bitstream[50000];static int bit[50000];//总的关系比特流static int a[50000];//存放非零元素的数组static int abit[50000];//存放非零元素数组的关系比特流static int b[50000];//存放零元素的数组static int bbit[50000];//存放零元素数组的关系比特流int l=0;int m,n,t=0;FILE *fp;if((fp=fopen("m8000-1out_high.wav","rb"))==NULL){ printf("cannot open file");exit(0);}i=0;while(!feof(fp)){ bitstream[i]=getc(fp);i++;}for(k=0;k<16;k++)printf("%d",bitstream[k]);k=0;m=0;n=0;for(j=0;j<i;j++){bit[k]=position(bitstream[j],bitstream[j+1]);k++;if(bitstream[j]){a[m]=bitstream[j];abit[m]=position(bitstream[j],bitstream[j+1]);m++;}else{b[n]=bitstream[j];bbit[n]=position(bitstream[j],bitstream[j+1]);n++;}}for(l=0;l<10;l++)printf("%d",abit[l]);printf("\n");for(l=0;l<10;l++)printf("%d",bbit[l]);ofstream out1("G723.1编码提零压缩后的比特流密文a.wav",ios::binary);//存放最终转换好的比特流文件if(!out1){ printf("Cannot open output file.\n!");return 1;}offset=0;out1.seekp(offset,ios::beg);for(t=0;t<=m-1;t++){ out1.write((char *)&a[t],2); }out1.close();ofstream out3("G723.1编码提零压缩后的零元素的数组b.wav",ios::binary);//存放最终转换好的比特流文件if(!out3){ printf("Cannot open output file.\n!");return 1;}offset=0;out3.seekp(offset,ios::beg);for(t=0;t<=n-1;t++){ out3.write((char *)&b[t],1); }out3.close();ofstream out4("G723.1编码提零压缩后的相对关系bbit.wav",ios::binary);//存放最终转换好的比特流文件if(!out4){ printf("Cannot open output file.\n!");return 1;}offset=0;out4.seekp(offset,ios::beg);for(t=0;t<=n-1;t++){ out4.write((char *)&bbit[t],1); }out4.close();ofstream out2("G723.1编码提零压缩后的相对关系abit.wav",ios::binary);//存放最终转换好的比特流文件if(!out2){ printf("Cannot open output file.\n!");return 1;}offset=0;out2.seekp(offset,ios::beg);for(t=0;t<=m-1;t++){ out2.write((char *)&abit[t],1); }out2.close();ofstream out5("G723.1编码提零压缩后的相对关系bit.wav",ios::binary);//存放最终转换好的比特流文件if(!out5){ printf("Cannot open output file.\n!");return 1;}offset=0;out5.seekp(offset,ios::beg);for(t=0;t<=k-1;t++){ out5.write((char *)&bit[t],1); }out5.close();return 0;}(二)BIT流展开和LSB嵌入程序代码#include"iostream.h"#include"math.h"#include"stdlib.h"#include"time.h"#include"stdio.h"#include"fstream.h"#include"io.h"char getword(FILE *fp){ int *s;int i;s=&i;s[0]=getc(fp);s[1]=getc(fp);return (i);}//读入一个字int main(){ static unsigned char alawbyte[5000000];//存放A率压缩后的样值 int channel=0,samplespersec=0,bitpersample=0;static int data[5000000];long offset=0;static int head[44];int i;int j=0;int k=0;long samples=0;static int bitstream[5000000];static int bitstream1[5000000];int l=0;int bit=0;static int group[8];ifstream in("f8000-1alaw.wav",ios::binary);if(!in){ cout<<"Cannot open input file.\n";return 1;}offset=0;in.seekg(offset,ios::beg);for(i=0;i<=28;i++)in.read((char *)&head[i],2);//将头文件读入HEAD数组中offset=54;in.seekg(offset,ios::beg);in.read((char *)&samples,4);offset=58;in.seekg(offset,ios::beg);for(i=0;i<=samples-1;i++){in.read((char *)&data[i],1);}//首先将数据全部读入data数组中in.close();FILE *fp;//此段程序读入G723.1编码压缩的密文比特流文件if((fp=fopen("G723.1编码去零压缩后的m8000-1out_high.wav","rb"))==NULL) {cout<<"cannot open file"<<endl;exit(0);}i=0;while(!feof(fp)){bitstream[i]=getword(fp);i++;}cout<<i-1<<endl;fclose(fp);l=0;k=0;while(k<i-1){ for(j=0;j<8;j++){bit=bitstream[k]&0x0080;if(bit==0){bitstream1[l]=0;l++;}else{bitstream1[l]=1;l++;}bitstream[k]<<=1;}k++; }//此段程序将bit流散开for(i=0;i<l;i++){cout<<bitstream1[i]<<' ';}for(i=0;i<=(l-1);i++){if(bitstream1[i]==1)//bitstream1[i]=1;{if(data[i]%2==0)data[i]=data[i]+1;elsedata[i]=data[i];}else if(bitstream1[i]==0)//bitstream1[i]=0;{if(data[i]%2==0)data[i]=data[i];elsedata[i]=data[i]-1;}}//进行LSB位的替换ofstream out1("LSB替换后的加密语音alaw.wav",ios::binary);if(!out1){cout<<"Cannot open output file.\n!";return 1;}offset=0;out1.seekp(offset,ios::beg);for(i=0;i<=28;i++){out1.write((char *)&head[i],2);}offset=58;out1.seekp(offset,ios::beg);for(i=0;i<=samples-1;i++){out1.write((char *)&data[i],1);}out1.close();return 0;}(三)提取程序代码#include"iostream.h"#include"math.h"#include"stdlib.h"#include"time.h"#include"stdio.h"#include"fstream.h"#include"io.h"int multiply(int k){int temp=1;for(int i=0;i<k;i++)temp*=2;return temp;}int main(){ static unsigned char alawbyte[5000000];//存放A率压缩后的样值 int channel=0,samplespersec=0,bitpersample=0;static int data[5000000];long offset=0;static int head[44];static int a[1000000];int i;int j=0;int k=0;int l=0;long samples=0;static int bitstream[5000000];static int bitstream1[5000000];static int bit[5000000];static int bit1[5000000][8];ifstream in("LSB替换后的加密语音alaw.wav",ios::binary);if(!in){ cout<<"Cannot open input file.\n";return 1;}offset=0;in.seekg(offset,ios::beg);for(i=0;i<=28;i++)in.read((char *)&head[i],2);//将头文件读入HEAD数组offset=54;in.seekg(offset,ios::beg);in.read((char *)&samples,4);cout<<"该文件样本数为:"<<samples<<endl;offset=58;in.seekg(offset,ios::beg);for(i=0;i<=samples-1;i++){in.read((char *)&data[i],1);}//首先将数据全部读入data数组中in.close();k=1;l=0;i=0;for(i=0;i<=samples-1;i++){if(data[i]%2==0){bit[l]=0;l++;}else{bit[l]=1;l++;}//cout<<bit[i]<<' ';// cout<<l<<endl;}for(i=0;i<=l;i++){bit1[(i/8)][i%8]=bit[i];}for(i=0;i<=(l/8);i++){a[i]=0;for(j=0;j<8;j++)a[i]+=bit1[i][j]*(multiply(7-j));}cout<<endl;// for(i=0;i<(l/8);i++)//cout<<a[i]<<' '<<endl;ofstream out1("恢复的压缩密文m8000-1out_high.wav",ios::binary);if(!out1){cout<<"Cannot open output file.\n!";return 1;}offset=0;out1.seekp(offset,ios::beg);k=0;for(i=0;i<=(l/8);i++){out1.write((char *)&a[i],2);k++;}out1.close();return 0;}(四)恢复源密文的程序代码#include"iostream.h"#include"math.h"#include"stdlib.h"#include"time.h"#include"stdio.h"#include"fstream.h"#include"io.h"char getword(FILE *fp){ int *s;int i;s=&i;s[0]=getc(fp);s[1]=getc(fp);return (i);}//读入一个字int main(){ static unsigned char alawbyte[5000000];//存放A率压缩后的样值static int data[5000000];long offset=0;int i;int j=0;int k=0;long samples=0;static int abit[5000000];static int bbit[5000000];static int c[5000000];static int d[5000000];static int e[5000000];int m=0;int n=0;int l=0;int t=0;int p=0;int q=0;int w=0;FILE *fp;if((fp=fopen("G723.1编码提零压缩后的相对关系abit.wav","rb"))==NULL) { cout<<"cannot open file"<<endl;exit(0);}i=0;while(!feof(fp)){ abit[i]=getc(fp);i++;}fclose(fp);//FILE *fp;if((fp=fopen("G723.1编码提零压缩后的相对关系bbit.wav","rb"))==NULL) { cout<<"cannot open file"<<endl;exit(0);}l=0;while(!feof(fp)){ bbit[l]=getc(fp);l++;}fclose(fp);//FILE *fp;if((fp=fopen("G723.1编码提零压缩后的零元素的数组b.wav","rb"))==NULL) { cout<<"cannot open file"<<endl;exit(0);}j=0;while(!feof(fp)){ c[j]=getc(fp);j++;}fclose(fp);//FILE *fp;if((fp=fopen("恢复的压缩密文m8000-1out_high.wav","rb"))==NULL){ cout<<"cannot open file"<<endl;exit(0);}k=0;while(!feof(fp)){ d[k]=getword(fp);k++;}fclose(fp);e[0]=d[0];t=0;m=1;n=1;p=1;q=0;for(m=1;m<i+l-2;m++){if(t==0){if(abit[p-1]==0){e[n]=d[p];n++;p++;}else{e[n]=c[q];n++;q++;t=1;}}else{if(bbit[q-1]==0){e[n]=c[q];n++;q++;}else{e[n]=d[p];n++;p++;t=0;}}}for(w=0;w<20;w++)cout<<e[w]<<endl;ofstream out1("G723.1解密的m8000-1out_high.wav",ios::binary);//存放最终转换好的比特流文件if(!out1){ cout<<"Cannot open output file.\n!";return 1;}offset=0;out1.seekp(offset,ios::beg);for(w=0;w<n;w++){ out1.write((char *)&e[w],1); } out1.close();return 0;}????????。

java小程序源代码

java小程序源代码

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;class CalculatorPanel extends JPanel implements ActionListener{public CalculatorPanel(){setLayout(new BorderLayout());display=new JTextField("0");display.setEditable(false);add(display,"Center");ope=new JTextField(" ");ope.setEditable(false);add(ope,"West");//创建菜单栏(暂时无实际意义)JMenuBar bar=new JMenuBar();add(bar,"North");JMenu view=new JMenu("查看(V)");JMenu edit=new JMenu("编辑(E)");JMenu help=new JMenu("帮助(H)");bar.add(view);bar.add(edit);bar.add(help);JMenuItem newItem=new JMenuItem("标准型(V)");JMenuItem newItem2=new JMenuItem("科学型(S)");JMenuItem newItem3=new JMenuItem("退出(E)");JMenuItem newItem4=new JMenuItem("关于..");view.add(newItem);view.add(newItem2);view.add(newItem3);help.add(newItem4);newItem4.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(null,"本程序由射手同学独立完成,请任何时候保留此句!");}});newItem3.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {int res;res=JOptionPane.showConfirmDialog(null, "确定退出?", "退出", JOptionPane.YES_NO_OPTION);if(res==JOptionPane.YES_OPTION) System.exit(0);}});JPanel p=new JPanel();p.setLayout(new GridLayout(4,4));String buttons="789/456*123-0.=+";for (int i=0;i<buttons.length();i++)addButton(p,buttons.substring(i,i+1));add(p,"South");}private void addButton(Container c,String s){JButton b=new JButton(s);// b.setSize()c.add(b);b.addActionListener(this);}public void actionPerformed(ActionEvent evt){String s=evt.getActionCommand();if ('0'<=s.charAt(0)&&s.charAt(0)<='9'){if(start)display.setText(s);else display.setText(display.getText()+s);start=false;}else//输入的是运算符,进行四则运算{double x=Double.parseDouble(display.getText());calculate(x);op=s;ope.setText(op);start=true;//重置文本框}}public void calculate(double n){if(op.equals("+")) arg+=n;else if (op.equals("-")) arg -=n;else if (op.equals("*")) arg*=n;else if (op.equals("/")) arg/=n;else if (op.equals("=")) arg=n;display.setText(""+arg);}//数据重置private boolean start=true;//是否是第一个输入private String op="=";//运算符private double arg=0;//运算结果private JTextField display;private JTextField ope;}class CalculatorFrame extends JFrame{public CalculatorFrame(){setTitle("Calculator");setLocation(500,200);setSize(200,200);setResizable(true);//关闭窗口事件响应,有两种方法setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 或者如下所示方法二// addWindowListener(new WindowAdapter()// {// public void windowClosing(WindowEvent e)// {// System.exit(0);// }//// });Container contentPane=getContentPane();contentPane.add(new CalculatorPanel());}}public class Calculator_2{ public static void main(String[] args) {JFrame frame=new CalculatorFrame(); frame.show();Calculator_2 a=new Calculator_2(); }}。

python固定资产管理程序源代码

python固定资产管理程序源代码

python固定资产管理程序源代码下面是一个简单的Python固定资产管理程序的源代码示例:```pythonclass Asset:def __init__(self, name, purchase_date, purchase_cost): = nameself.purchase_date = purchase_dateself.purchase_cost = purchase_costdef compute_depreciation(self, depreciation_rate):# 根据折旧率计算资产的折旧depreciation = self.purchase_cost * depreciation_rate return depreciationdef display_info(self):print(f'资产名称: {}')print(f'购买日期: {self.purchase_date}')print(f'购买成本: {self.purchase_cost}')class AssetManager:def __init__(self):self.assets = []def add_asset(self, asset):# 添加新资产到资产列表中self.assets.append(asset)def remove_asset(self, asset):# 从资产列表中删除指定的资产self.assets.remove(asset)def calculate_depreciation(self, depreciation_rate): for asset in self.assets:depreciation =pute_depreciation(depreciation_rate)print(f'资产: {}, 折旧金额: {depreciation}')def display_assets(self):for asset in self.assets:asset.display_info()print('-------------------------')# 示例代码manager = AssetManager()# 添加一些资产asset1 = Asset('计算机', '2020-01-01', 2000)asset2 = Asset('打印机', '2019-06-15', 800)manager.add_asset(asset1)manager.add_asset(asset2)# 显示所有资产信息manager.display_assets()# 计算资产折旧depreciation_rate = 0.1manager.calculate_depreciation(depreciation_rate)```这个程序包括两个类:`Asset`和`AssetManager`。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档