當前位置:首頁 » 編程語言 » 沈陽理工c語言課程設計
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

沈陽理工c語言課程設計

發布時間: 2022-05-31 11:39:29

『壹』 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);
}