‘壹’ c语言程序课程设计
给你代码,你自己去研究吧
#include <stdio.h>
#define SIZE 10
typedef struct student
{
int num;
char name[20];
int score[3];
float average;
}student;
void indata(student *stu)
{
int i;
for (i = 0; i < SIZE; i++)
{
scanf("%d %s %d %d %d%*c", &stu[i].num, stu[i].name, &stu[i].score[0],
&stu[i].score[1], &stu[i].score[2]);
}
}
void outdata(student *stu)
{
int i;
for (i = 0; i < SIZE; i++)
{
printf("%d %s %d %d %d %f\n", stu[i].num, stu[i].name, stu[i].score[0],
stu[i].score[1], stu[i].score[2], stu[i].average);
}
}
int main()
{
student stu[SIZE];
int i, j;
int t;
student temp;
printf("请输入信息:\n");
indata(stu);
for (i = 0; i < SIZE; i++) //算平均分
{
stu[i].average = 0;
for (j = 0; j < 3; j++)
stu[i].average += stu[i].score[j];
stu[i].average /= 3;
}
for (i = 0; i < SIZE - 1; i++) //按平均分进行排序
{
t = i;
for (j = i + 1; j < SIZE; j++)
{
if (stu[t].average > stu[j].average)
t = j;
}
if (t == i)
continue;
else
{
temp = stu[i];
stu[i] = stu[t];
stu[t] = temp;
}
}
printf("排序后信息为:\n");
outdata(stu);
return 0;
}
‘贰’ 沈阳理工大学信息科学与工程学院c语言程序设计题库
可以提供些资料给你,如果还是不会写的话
‘叁’ 跪求C语言程序设计高手编一个程序
三、 源代码
#include<iostream>
#include<string>
using namespace std;
class infor
{
protected:
string snames;
string sid;
int ssex;
string saddr;
string sphoneno;//电话
public:
void input();
void src();//显示
void inall();//统计
void select();//查询
void del();//删除
void alter();//修改
};
void infor::input()
{
int j;
for(j=1;j<=1;j=j+1)
{
cin>>snames>>sid>>ssex>>saddr>>sphoneno;
string sex;
if(ssex==1)
{
sex="男";
}
else if(ssex==2)
{
sex="女";
}
else
{
cout<<"错误,重新输入。\n";
break;
}
cout<<"\t"<<"姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"家庭住"<<"\t"<<"电话号码"<<endl;
cout<<"\t"<<snames<<"\t"<<sid<<"\t"<<sex<<"\t"<<saddr<<"t"<<sphoneno<<endl;
ofstream data("data.txt",ios_base::app);
data<<setw(10)<<snames<<setw(10)<<sid<<setw(10)<<sex<<setw(10)<<saddr<<setw(20)<<sphoneno<<endl;
}
}
void infor::src()
{
char ch;
ifstream da("data.txt");
cout<<"\t"<<"姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"家庭住址"<<"\t"<<"电话号码"<<endl;
while (da.get(ch))
cout << ch;
da.close();
}
void infor::inall()
{ int m,n=-1;
cin>>m;
if(m==1)
{
infor s33;
ifstream da("data.txt",ios_base::in);
string sex;
while(da.eof()==0)
{
da>>s33.snames>>s33.sid>>sex>>s33.saddr>>s33.sphoneno;
n++;
}
da.close();
cout<<"共有联系人:"<<n<<endl;
}
else if(m==2)
{
infor s33;
ifstream da("data.txt",ios_base::in);
int male=0,female=0;
string name,id,sex;
while(da.eof()==0)
{
da>>name>>id>>sex;
if (sex=="男")
{
da>>s33.snames>>s33.sid>>sex>>s33.saddr>>s33.sphoneno;
male++;
}
else if(sex=="女")
{
da>>s33.snames>>s33.sid>>sex>>s33.saddr>>s33.sphoneno;
female++;
}
}
cout<<"男生有"<<male<<"人\n";
cout<<"女生有"<<female<<"人\n";
da.close();
}
else
{
cout<<"Error!!!\n";
}
}
void infor::select()
{
infor s44;
string name,id,sex;
int m;
cin>>m;
ifstream da("data.txt",ios_base::in);
if(m==1)
{
cout<<"输入要查询学号:\n";
cin>>id;
while(da.eof()==0)
{
da>>s44.snames>>s44.sid>>sex>>s44.saddr>>s44.sphoneno;
if(s44.sid==id)
{
cout<<" "<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"性别"<<setw(15)<<"家庭住址"<<setw(15)<<"电话号码"<<endl;
cout<<"\t"<<s44.snames<<"\t"<<s44.sid<<"\t"<<sex<<"\t"<<s44.saddr<<"\t"<<s44.sphoneno<<endl;
}
else
{
cout<<"Error!!!\n";
break;
}
}
da.close();
}
else if(m==2)
{
cout<<"输入要查询姓名:\n";
cin>>name;
while(da.eof()==0)
{
da>>s44.snames>>s44.sid>>sex>>s44.saddr>>s44.sphoneno;
if(s44.snames==name)
{
cout<<" "<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"性别"<<setw(15)<<"家庭住址"<<setw(15)<<"电话号码"<<endl;
cout<<"\t"<<s44.snames<<"\t"<<s44.sid<<"\t"<<sex<<"\t"<<s44.saddr<<"\t"<<s44.sphoneno<<endl;
}
else
{
cout<<"Error!!!\n";
break;
}
}
da.close();
}
else
{
cout<<"Error!!!\n";
}
}
void infor::del()
{
ifstream inData("data.txt", ios_base::in);
ofstream outData("cookie.txt",ios_base::app);
if (!outData || !inData)
{
cout <<endl <<"对不起!!!!找不到文件!!!!" <<endl;
return;
}
string sign;
cout <<endl <<"你要删除联系人的姓名或学号:";
cin >>sign;
bool flag = true;
string str;
while (inData >>snames >>sid)
{
getline(inData, str);
if ((sign==snames) || (sign==sid))
{
cout <<endl <<"你想删除的联系人:" <<endl <<endl;
cout <<setiosflags(ios::left) <<setw(17) <<snames<<" " <<sid <<str <<endl;
flag = false;
break;
}
outData <<setiosflags(ios::left) <<setw(17) <<snames <<" " <<sid <<str <<endl;
}
if (flag)
{
cout <<endl <<"对不起!!!联系人中没你找的人!!!!" <<endl <<endl;
}
else
{
while (getline(inData, str))
{
outData <<str <<endl;
}
outData.close();
inData.close();
ifstream in("cookie.txt", ios::in);
ofstream out("data.txt", ios::out);
if (!out || !in)
{
cout<<endl<<"对不起不能打开文件!!!"<<endl<<endl;
return;
}
while (getline(in, str))
{
out<<str<<endl;
}
out.close();
in.close();
cout <<endl <<"这个人的信息已经从你的通迅录中删除!!!" <<endl <<endl;
}
}
void infor::alter()
{
ifstream inData("data.txt", ios_base::in);
ofstream outData("cookie.txt",ios_base::out);
if (!outData || !inData)
{
cout <<endl <<"对不起!!!!找不到文件!!!!" <<endl;
return;
}
string sign;
cout <<endl <<"你要修改的联系人的姓名或学号:";
cin >>sign;
bool flag = true;
string str;
while (inData >>snames >>sid)
{
getline(inData, str);
if ((sign==snames) || (sign==sid))
{
cout <<endl <<"你想修改的联系人:" <<endl <<endl;
cout <<setiosflags(ios::left) <<setw(17) <<snames
<<" " <<sid <<str <<endl;
flag = false;
break;
}
outData<<setiosflags(ios::left)<<setw(17)<<snames<<" "<<sid<<str<<endl;
}
if (flag)
{
cout <<endl <<"对不起!!!联系人中没你找的人!!!!" <<endl <<endl;
}
else
{
while (getline(inData, str))
{
outData <<str <<endl;
}
outData.close();
inData.close();
ifstream in("cookie.txt", ios::in);
ofstream out("data.txt", ios::out);
if (!out || !in)
{
cout <<endl <<"对不起不能打开文件!!!" <<endl <<endl;
return;
}
while (getline(in, str))
{
out <<str <<endl;
}
out.close();
in.close();
{
cout<<"重新输入信息:\n";
{
int j;
for(j=1;j<=1;j=j+1)
{
cin>>snames>>sid>>ssex>>saddr>>sphoneno;
string sex;
if(ssex==1)
sex="男";
else if(ssex==2)
sex="女";
else
{
cout<<"错误\n";
break;
}
cout<<"\t"<<"姓名"<<"\t"<<"学号"<<"\t"<<"性别"<<"\t"<<"家庭住址"<<"\t"<<"电话号码"<<endl;
cout<<"\t"<<snames<<"\t"<<sid<<"\t"<<sex<<"\t"<<saddr<<"t"<<sphoneno<<endl;
ofstream data("data.txt",ios_base::app);
data<<setw(10)<<snames<<setw(15)<<sid<<setw(10)<<sex<<setw(10)<<saddr<<setw(20)<<sphoneno<<endl;
} } } } }
information.cpp
#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
#include"infor.h"
using namespace std;
int main()
{
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
//int i;
for(;;)//(i=0;i<=6;i=i+1)
{ int c; //c是对菜单的选择
cin>>c;
{if(c==1)
{
cout<<"添加联系人:\n";
cout<<"\n";
cout<<"|姓名|"<<"|学号|"
<<"|性别(1/2)|"<<"|家庭住址|"
<<"|联系电话|\n";
cout<<"\n";
infor s1;
s1.input();
cout<<"\n";
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
cout<<"\n";
}
else if(c==2)
{
cout<<"显示所有联系人!\n";
cout<<"\n";
infor s2;
s2.src();
cout<<"\n";
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
cout<<"\n";
}
else if(c==3)
{
cout<<"统计:1.统计总人数;2.按性别统计。"<<endl;
cout<<"\n";
infor s3;
s3.inall();
cout<<"\n";
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
cout<<"\n";
}
else if(c==4)
{
cout<<"查询:1.按学号查询;2.按姓名查询。\n";
cout<<"\n";
infor s4;
s4.select();
cout<<"\n";
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
cout<<"\n";
}
else if(c==5)
{
cout<<"\n";
infor s5;
s5.del();
cout<<"\n";
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
cout<<"\n";
}
else if(c==6)
{
infor s6;
s6.alter();
cout<<"\n";
cout<<" 基于C++学生通信录管理系统 |\n";
cout<<"--------------------------------|\n";
cout<<"请选择要执行的选项: |\n";
cout<<"--------------------------------|\n";
cout<<"1.添加联系人!"<<setw(20)<<"2.显示所有联系人!|\n";
cout<<" |\n";
cout<<"3.分类统计! "<<setw(20)<<"4.分类查询! |\n";
cout<<" |\n";
cout<<"5.删除联系人!"<<setw(20)<<"6.修改信息! |\n";
cout<<" |\n";
cout<<"7.退出系统!\n";
cout<<"\n";
}
else if(c==7)
exit(0);
else
{
cout<<"error!!!\n";
break;
}
}
}
}
‘肆’ C语言程序课程设计
#include <stdio.h>
#define MAX 200
int main()
{
int a[MAX][MAX],n;
void initmatrix(int a[][MAX]);//初始化矩阵,将所有元素赋0
void creatematrix_2k1(int a[][MAX],int n);//生成2n+1阶幻方
void creatematrix_4k(int a[][MAX],int n);//生成4n阶幻方
void creatematrix_4k2(int a[][MAX],int n);//生成4n+2阶幻方
void outputmatrix(int a[][MAX],int n);//输出n阶幻方
initmatrix(a);
printf("please input a interger number:");
scanf("%d",&n);
if(n%2) creatematrix_2k1(a,(n-1)/2);
else {if(n%4==0) creatematrix_4k(a,n/4);
else creatematrix_4k2(a,(n-2)/4);}
outputmatrix(a,n);
return 0;
}
void initmatrix(int a[][MAX])
{
for(int i=0;i<MAX;i++)
for(int j=0;j<MAX;j++)
a[i][j]=0;
}
void outputmatrix(int a[][MAX],int n)
{
for(int i=0;i<n;i++)
{
printf("第%-3d行的数依次为:",i+1);
for(int j=0;j<n;j++)
printf("%-5d",a[i][j]);
printf("\n");
}
}
void creatematrix_2k1(int a[][MAX],int n)
{
int col=-1,row=-1;
int *p,*q;
p=&col,q=&row;
void fillmatrix(int a[][MAX],int *p,int *q,int n,int i);//将i填入2n+1阶幻方中
for(int i=1;i<=((2*n+1)*(2*n+1));i++)
fillmatrix(a,p,q,n,i);
}
void fillmatrix(int a[][MAX],int *p,int *q,int n,int i)
{
if(i==1)
{
a[0][n]=i;
*p=0,*q=n;
}
else
{
if((*p==0&&*q==2*n)||a[(*p+2*n)%(2*n+1)][(*q+1)%(2*n+1)])
{
a[(*p+1)%(2*n+1)][*q]=i;
*p=(*p+1)%(2*n+1);}
else{a[(*p+2*n)%(2*n+1)][(*q+1)%(2*n+1)]=i;
*p=(*p+2*n)%(2*n+1),*q=(*q+1)%(2*n+1);}
}
}
void creatematrix_4k(int a[][MAX],int n)
{
int temp;
for(int i=0;i<4*n;i++)
{ for(int j=0;j<4*n;j++)
a[i][j]=4*n*i+j+1;}
for(i=0;i<4*n;i++)
for(int j=0;j<4*n;j++)
if((i>j)&&((i-j)%4==0||(i+j+1)%4==0))
{temp=a[i][j];
a[i][j]=a[4*n-1-i][4*n-1-j];
a[4*n-1-i][4*n-1-j]=temp;}
for(i=0;i<2*n;i++)
{temp=a[i][i];
a[i][i]=a[4*n-1-i][4*n-1-i];
a[4*n-1-i][4*n-1-i]=temp;}
}
void creatematrix_4k2(int a[][MAX],int n)//构造4n+2阶幻方
{
int col=-1,row=-1,i;
int exn=(2*n+1)*(2*n+1);
int *p,*q;
p=&col,q=&row;
void fillmatrix_2(int a[][MAX],int *p,int *q,int cs, int rs,int n,int i);/*将i填入以a[cs][rs]为起始的2n+1阶幻方中,用p,q返回的i-1行列值*/
for(i=1;i<=exn;i++)
fillmatrix_2(a,p,q,0,0,n,i);
for(i=exn+1;i<=exn*2;i++)
fillmatrix_2(a,p,q,2*n+1,2*n+1,n,i);
for(i=2*exn+1;i<=3*exn;i++)
fillmatrix_2(a,p,q,0,2*n+1,n,i);
for(i=3*exn+1;i<=4*exn;i++)
fillmatrix_2(a,p,q,2*n+1,0,n,i);
void lastswap(int a[][MAX],int n);//对4n+2阶幻方做最后的变换
lastswap(a,n);
}
void fillmatrix_2(int a[][MAX],int *p,int *q,int cs, int rs,int n,int i)
{
int exn=(2*n+1)*(2*n+1);
if(i%exn==1)
{
a[cs+0][rs+n]=i;
*p=0,*q=n;
}
else {if((*p==0&&*q==2*n)||a[(*p+2*n)%(2*n+1)+cs][(*q+1)%(2*n+1)+rs])
{
a[(*p+1)%(2*n+1)+cs][*q+rs]=i;
*p=(*p+1)%(2*n+1);
}
else{
a[(*p+2*n)%(2*n+1)+cs][(*q+1)%(2*n+1)+rs]=i;
*p=(*p+2*n)%(2*n+1),*q=(*q+1)%(2*n+1);
}
}
}
void lastswap(int a[][MAX],int n)
{
int temp,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{temp=a[i][j];
a[i][j]=a[2*n+1+i][j];
a[2*n+1+i][j]=temp;}
for(i=1;i<=n;i++)
{temp=a[n][i];
a[n][i]=a[3*n+1][i];
a[3*n+1][i]=temp;}
for(i=n+1;i<2*n+1;i++)
for(j=0;j<n;j++)
{temp=a[i][j];
a[i][j]=a[2*n+1+i][j];
a[2*n+1+i][j]=temp;}
for(i=0;i<2*n+1;i++)
for(j=4*n+1;j>3*n+2;j--)
{temp=a[i][j];
a[i][j]=a[2*n+1+i][j];
a[2*n+1+i][j]=temp;}
}
求幻方的程序
#include <stdio.h>
#include <stdlib.h>
#define IO "%d"//和下面一行共同扩展数据成员的格式
typedef int ElemType;//同上
typedef struct LinkNode
{
ElemType data;
struct LinkNode *next;
}LinkNode,*Link;
Link creat();//建立带头结点的链表,并返回头指针
void print(Link);//输出链表所有结点
bool insert(Link,int ,ElemType);//向head为头指针的链表中插入元素e使之成为链表第i个元素成功返回TRUE否则FALSE
bool del(Link,int );//在head为头指针的链表中删除第i个结点,成功返回TRUE否则返回FALSE
void operate(Link);//在本程序中进行链表的插入,删除,输出操作
Link creat()
{
Link head=(Link)malloc(sizeof(LinkNode));
Link pre=head,p;
int count=1;
char ch;
printf("是否终止建立链表(Y/N):");
scanf("%c",&ch);
while(ch=='n'||ch=='N')
{
p=(Link)malloc(sizeof(LinkNode));
printf("请输入第%d个结点内的数据:",count);
scanf(IO,&(p->data));
fflush(stdin);
pre->next=p;
pre=p;
printf("是否终止建立链表(Y/N):");
scanf("%c",&ch);
count++;
}
pre->next=NULL;
return head;
}
void print(Link head)
{
printf("链表目前情况为:\n");
Link p=head->next;
int count=1;
while(p)
{
printf("第%d个结点中数据为"IO" ",count,p->data);
p=p->next;
if((count++)%3==0)printf("\n");
}
if(count%3!=1)printf("\n");
}
bool insert(Link head,int i,ElemType e)
{
Link pre,p;
int k;
for(k=0,pre=head;k<i-1&⪯k++,pre=pre->next);//寻找第i-1个元素的指针
if(k!=i-1||(!pre))return false;
p=(Link)malloc(sizeof(LinkNode));
p->data=e;
p->next=pre->next;
pre->next=p;
return true;
}
bool del(Link head,int i)
{ Link pre,p;
int k;
for(k=0,pre=head,p=head->next;k<i-1&&p;k++,pre=p,p=p->next);//寻找第i-1个元素的指针
if(k!=i-1||(!p))return false;
pre->next=p->next;
free(p);
return true;
}
void operate(Link head)
{
int n,i;
ElemType e;
do
{
printf("************************************************\n");
printf("请输入想进行何种操作\n1============插入结点\n2============删除结点\n3============输出链表\n");
scanf("%d",&n);
switch(n)
{
case 1:printf("现在进行结点插入\n");
printf("请输入欲插入到何位置:");scanf("%d",&i);
printf("请输入欲插入的数据:");scanf(IO,&e);
if(insert(head,i,e))printf("插入成功!\n");else printf("插入失败!\n");
break;
case 2:printf("现在进行结点删除\n");
printf("请输入欲删除结点位置:");scanf("%d",&i);
if(del(head,i))printf("删除成功!\n");else printf("删除失败!\n");
break;
case 3:print(head);break;
default:break;
}
}while(n<4&&n>0);
}
int main()
{
Link head=creat();
operate(head);
return 0;
}
链表的操作
#include <stdio.h>
#include <math.h>//求积分
int main()
{
double f1(double);
double f2(double);
double f3(double);
double f4(double);
double f5(double);
double (*p)(double);
double integral(double a,double b,double(*p)(double));
double a,b;//记录积分区间
printf("请输入积分区间:");
scanf("%lf %lf",&a,&b);
if(a>b){double temp=a;a=b;b=temp;}//确保a<b
printf("sin(x)在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,sin));
printf("cos(x)在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,cos));
printf("exp(x)在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,exp));
printf("x+1在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,f1));
printf("2x+3在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,f2));
printf("exp(x)+1在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,f3));
printf("(1+x)^2在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,f4));
printf("x^3在[%lf,%lf]上的积分值为%lf\n",a,b,integral(a,b,f5));
return 0;
}
double integral(double a,double b,double(*p)(double))
{
double sum=0,l=b-a,pl;//sum保存积分和,l保存积分区间的长度,pl保存积分区间细分后每个小区间的长度
int n=2,i;//n保存划分的小区间数i用作累加指针
pl=l/n;
while(pl>1e-6)
{
sum=0;
for(i=0;i<n;i++)
sum+=(*p)(a+i*pl)*pl;
n*=2;
pl/=2;
}
return sum;
}
double f1(double x)
{
return x+1;
}
double f2(double x)
{
return 2*x+3;
}
double f3(double x)
{
return exp(x)+1;
}
double f4(double x)
{
return (1+x)*(1+x);
}
double f5(double x)
{
return x*x*x;
}
求积分
都是以前写的 便宜楼主了!!
‘伍’ 《C语言程序设计》课程设计
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define BUFFERSIZE 1024
#define MAXACCOUNT 1000
typedef struct BankAccount
{
int account;
int key;
char name[32];
float balance;
}BANKACCOUNT;
BANKACCOUNT accountCollection[MAXACCOUNT];
int curAccount = 0;
void InsertAccount(FILE *fp)
{
BANKACCOUNT newaccount;
printf("please input the account information\n");
printf(">>account num:");
scanf("%d",&(newaccount.account));
printf(">>key:");
scanf("%d",&(newaccount.key));
printf(">>name:");
scanf("%s",newaccount.name);
printf(">>balance:");
scanf("%f",&(newaccount.balance));
fseek(fp,0L,SEEK_END);
fprintf(fp,"%d %d %s %.2f\n",newaccount.account,newaccount.key,newaccount.name,newaccount.balance);
}
void GetAccount(FILE *fp)
{
int accountnum;
int key;
char name[32];
float balance;
int i =0,j;
char buffer[BUFFERSIZE];
int len;
curAccount = 0;
fseek(fp,0,SEEK_SET);
while(!feof(fp)) /* 因为feof()最后会读2遍,所以最后curAccount多加了1 */
{
fscanf(fp,"%d %d %s %f",&accountnum,&key,name,&balance);
accountCollection[curAccount].account = accountnum;
accountCollection[curAccount].key = key;
strcpy(accountCollection[curAccount].name ,name);
accountCollection[curAccount].balance = balance;
curAccount++;
}
}
void ListAccount(FILE *fp)
{
int i =0;
printf("There is %d accounts at all:\n",curAccount-1);/* curAccount减去多加的1 */
for(i = 0;i< curAccount-1;i++)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
}
}
int SearchAccount(FILE *fp,int accountnum)
{
int i =0;
for(i = 0;i< curAccount-1;i++)
{
if(accountCollection[i].account == accountnum)
{
printf("ACCOUNT[%d]:\n",i+1);
printf("account:%d\n",accountCollection[i].account);
printf("name:%s\n",accountCollection[i].name);
printf("balance:%.2f\n",accountCollection[i].balance);
return 1;
}
}
return 0;
}
void DelAccount(FILE *fp,int accountnum)
{
int i;
if(SearchAccount(fp,accountnum)==0)
printf("Can't find the account\n");
else
{
for(i = 0;i<curAccount-1;i++)
{
if(accountCollection[i].account != accountnum)
fprintf(fp,"%d %d %s %.2f\n",accountCollection[i].account,accountCollection[i].key,accountCollection[i].name,accountCollection[i].balance);
}
printf("delete successfully!\n");
}
}
int main()
{
FILE *fp;
int accountnum;
int i;
do{
system("cls"); //清屏
puts("********************************************");
puts("* You can choose : *");
puts("* 1 : Insert a new Account *");
puts("* 2 : List all Accounts *");
puts("* 3 : Find a Account *");
puts("* 4 : Delete a Account *");
puts("* 5 : quit *");
puts("********************************************");
printf("Please input your choice:");
scanf("%d",&i);
system("cls"); //清屏
switch(i)
{
case 1:
if(!(fp = fopen("account.txt","a+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
InsertAccount( fp);
printf("press any key to continue.....\n");
getch();
fclose(fp);
break;
case 2:
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
ListAccount(fp);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 3:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
if(!SearchAccount(fp,accountnum))
printf("There is not the account:%d\n",accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
case 4:
printf("please input the account num:\n");
scanf("%d",&accountnum);
if(!(fp = fopen("account.txt","r")))
{
printf("can't open the file account.txt\n");
exit(0);
}
GetAccount(fp);
fclose(fp);
if(!(fp = fopen("account.txt","w+")))
{
printf("can't open the file account.txt\n");
exit(0);
}
DelAccount(fp,accountnum);
fclose(fp);
printf("press any key to continue.....\n");
getch();
break;
default:
break;
}
}while(i != 5);
return 0;
}
账户数据文件名已经设定为account.txt,这个文件要和上面这个程序放在同一个文件夹下面,不然就得用绝对路径(比如"d:\\book\\account.txt"),account内容可以用记事本打开自己改动,然后运行程序后就可以在程序中添加或删除
‘陆’ C语言程序设计
一些废话!
‘柒’ c语言课程设计实例
#include<iostream.h>
void main()
{
char a[12][9]={{'j','a','n','u','a','r','y'},{'F','e','b','r','u','a','r','y'},{'m','a','r','c','h'},{'a','p','r','i','l'},{'m','a','y'},{'j','u','n','e'},{'j','u','l','y'},{'a','u','g','u','s','t'}, {'s','e','p','t','e','m','b','e','r'},{'o','c','t','o','b','e','r'},{'n','o','v','e','m','b','e','r'},{'D','e','c','e','m','b','e','r'}},(*p)[9]=a;
int b;
cout<<"输入月份:";
cin>>b;
cout<<"该月的英文单词是:"<<*(p+b-1)<<endl;
}
程序写到这分上,我都想自杀了.......用字符串应该会简单些,可是我没想好..只能这样了..
‘捌’ 沈阳理工大学的计算机科学与技术有哪些课程
大一:C语言,
大外
,
高数
,
大二:C++,电路,数据结构,大外,离散数学,
大三:数据库,计算机组成原理,操作系统,
编译原理
,计算机网络,软件工程
大四:主要是毕业设计了,没有什么主要课程
‘玖’ c语言程序设计
c语言程序设计
悬赏分:0 - 离问题结束还有 5 天 22 小时
一.训练目的:
计算机程序设计训练是学习完《计算机程序设计》课程后进行的一次全面的综合性上机实验。其目的在于为学
生提供了一个既动手又动脑,独立实践的机会,将课本上的理论知识和实际有机的结合起来,锻炼学生的分析
解决实际问题的能力。提高学生适应实际,实践编程的能力。
二.设计要求:
1. 按照给定题目独立设计程序,上机调试通过。
2. 写出设计报告
提交报告的内容如下:
1)题目内容的描述
2)应用程序功能的详细说明
3)输入数据类型、格式和内容限制;
4)主要模块的算法描述
–以程序流程图的方式给出
–简要的语言描述
5)结束语
6)程序的源代码清单
7)报告的字数,不算源代码清单不少于4页
按规定的模板封面输出,不准自定义封面格式
提交报告的格式如下:
1)正文宋体小四号字
2)每个自然段开始空两格.
3)文中英文用新罗马(time new roman),四号
4)源程序清单用英文新罗马五号
5)提交报告封面使用《沈阳理工大学课程设计(论文)》专用封面
注:对于程序中未能实现的部分需要加以说明。对于程序中所参考的部分代码需要加以声明,并说明出处。
题目35
题目:销售管理系统
某公司有四个销售员(编号:1-4),负责销售五种产品(编号:1-5)。每个销售员都将当天出售的每种产品
各写一张便条交上来。每张便条包含内容:
1)销售员的代号
2)产品的代号
3)这种产品的当天的销售额
每位销售员每天可能上缴0-5张便条。假设,收集到了上个月的所有便条,编写一个处理系统,读取上个月的销
售情况(自己设定),进行如下处理。
1)计算上个月每个人每种产品的销售额。
2)按销售额对销售员进行排序,输出排序结果(销售员代号)
3)统计每种产品的总销售额,对这些产品按从高到底的顺序,输出排序结果(需输出产品的代号和销售额)
4)输出统计报表
销售统计报表
产品代号
销售员代号 1 2 3 4 5 销售之和
1
2
3
4
每种产品之和 总和
二.技术要求
1. 按照给定题目独立设计程序,上机调试通过。
2. 写出设计报告
提交报告的内容如下:
1)题目内容的描述
2)应用程序功能的详细说明
3)输入数据类型、格式和内容限制;
4)主要模块的算法描述
–以程序流程图的方式给出
–简要的语言描述
5)结束语
6)程序的源代码清单
7)报告的字数,不算源代码清单不少于4页
按规定的模板封面输出,不准自定义封面格式
提交报告的格式如下:
1)正文宋体小四号字
2)每个自然段开始空两格.
3)文中英文用新罗马(time new roman),四号
4)源程序清单用英文新罗马五号
5)提交报告封面使用《沈阳理工大学课程设计(论文)》专用封面
注:对于程序中未能实现的部分需要加
‘拾’ y=((a*x+b)*x+c)*x+d c语言程序设计课设 沈阳理工大学 机械系
#include<stdio.h>
void fun( float a,float b,float c,float d,float x)
{
float y;
y=((a*x+b)*x+c)*x+d;
printf("%f",y);
}
void main()
{
float a,b,c,d, x;
printf("input a,b,c,d,x\n");
scanf("%f%f%f%f%f",&a,&b,&c,&d,&x);
fun(a,b,c,d,x);
}