⑴ 数据结构与算法C语言的一段代码
struct 不能这样赋值吧
⑵ c语言如何运算面积,周长
代码如下:
#include<stdio.h>
int main()
{
float a,b,c,d;
scanf("%f %f",&a,&b);//输入长和宽
c=a*b;
d=2*(a+b);
printf("S=%.2f L=%.2f
",c,d);//S是面积,L是周长
return 0;
}
(2)火焰面积特性增长算法c语言代码扩展阅读:
C语言是一门通用计算机编程语言,广泛应用于底层开发。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。
尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。
二十世纪八十年代,为了避免各开发厂商用的C语言语法产生差异,由美国国家标准局为C语言制定了一套完整的美国国家标准语法,称为ANSI C,作为C语言最初的标准。[1]目前2011年12月8日,国际标准化组织(ISO)和国际电工委员会(IEC)发布的C11标准是C语言的第三个官方标准,也是C语言的最新标准,该标准更好的支持了汉字函数名和汉字标识符,一定程度上实现了汉字编程。
C语言是一门面向过程的计算机编程语言,与C++,Java等面向对象的编程语言有所不同。
⑶ 设计C语言程序,游戏规则:21根火柴,一次只能拿走1或2或3或4根,不能不拿不能弃权,人与电脑比赛。
#include<stdio.h>
int f(int n){
switch(n){
case 0:return 4;
case 4:return 3;
case 3:return 2;
case 2:return 1;
}
return 0;
}
void main(){
int m=21,n;
do{
scanf("%d",&n);
m-=n;
n=f(m%5);
printf ("%d\n",n);
m-=n;
}while(m>1);
}
其实有更简单的,如下:
#include<stdio.h>
void main(){
int n;
do{
scanf("%d",&n);
printf ("%d\n",5-n);
}while(1);
}
⑷ C语言的问题!十万火急!
你的程序有问题,Merge(int a[],int m,int b[],int n)这个函数里的c[],是新定义的,对主函数的c【】不会产生影响。应该把c【】,最为一个参数传递给Merge函数。
一下是修改过的程序,运行过了没有任何问题,有什么问题可以交流下。
#include <stdio.h>
#define M 5
#define N 5
void main()
{
int i;
int a[M],b[N],c[M+N];
void Merge(int a[],int m,int b[],int n,int c[]);
printf("请输入一个序列:\n");
for(i=0;i<M;i++)
scanf("%d",&a[i]);
printf("请输入一个序列:\n");
for(i=0;i<N;i++)
scanf("%d",&b[i]);
Merge(a,M,b,N,c);
for(i=0;i<M+N;i++)
printf("%d, ",c[i]);
printf("\n");
}
void Merge(int a[],int m,int b[],int n,int c[])
{
int i=0,j=0,k=0;
while(i<m&&j<n)
{
if(a[i]<=b[j])
{
c[k]=a[i];
i++; k++;
}
else
{
c[k]=b[j];
j++; k++;
}
}
while(j<n)
{
c[k++]=b[j++];
}
while(i<m)
{
c[k++]=a[i++];
}
}
⑸ 如何用C语言制作一个3D的动态火焰效果
嗯,我来说两句。
C语言是可以实现火焰粒子特效的
你的创作思路是:在网上搜集关于火焰粒子特效的文章,比如网络文库,新浪文库、
然后着手编程
编程要注意,既然是C,你可以包含DirectX的库,然后调用别人写好的库函数实现一些基本功能,比如画点,上色,定时,Z缓存,你可以搜directx的使用说明,多得很
动态火焰效果是游戏编程的一部分,额。。涉及挺多的东西,代码无法给你,抱歉
⑹ 两道编程算法题(两图一道),题目如下,可以给出算法思路或者源代码,源代码最好是C语言的
就会个第一题(因为第一题上已经给出了大致思路)
思路:用map容器(它的内部数据结构是一颗红黑树,查找和插入数据速度非常快)
map<int,st>a;//key(int):设置为1~n的数;value(st):设置为key的前驱和后继;
这样一来就可以像链表快速插入数据,又可以像数组随机访问元素(key,就相当于数组的下标)
下面是代码和运行截图;
看代码前建议先了解一下map容器的具体用法;
#include<iostream>
#include<map>
#include<vector>
using namespace std;
struct st{//两个成员变量用来储存前驱和后继
int left;//0
int right;//1
st()
{
left=0;
right=0;
}
};
void input(map<int,st> &a)//输出
{
st t;
int s=0;
map<int,st>::iterator it;//迭代器(指针)
for(it=a.begin();it!=a.end();it++)//循环迭代
{
t=it->second;
if(t.left==0)//左边等于0,说明该数是第一个数
{
s=it->first;//记录key
break;
}
}
t=a[s];
cout<<s<<" ";
while(t.right!=0)//循环找当前数的右边的数(右边的为0,就说明该数是最后一个数)
{
cout<<t.right<<" ";
t=a[t.right];
}
}
int main()
{
st t,t_i,t_x,t_k,s;
map<int,st>a;
map<int,st>::iterator it;
int n,x,p,x_l,x_r;
cin>>n;
for(int i=1;i<=n;i++)//map容器赋初值(i,t)
//i:(key)下标;t:(value)结构体变量
{
a.insert(make_pair(i,t));
}
for(int i=2;i<=n;i++)
{
cin>>x>>p;
if(p==0)//x的左边插入i
{
t=a[x];
if(t.left==0)//x的左边没有数
{
t_x.left=i;
t_i.right=x;
a[x]=t_x;
a[i]=t_i;
}
else//x的左边有数
{
int x_left;
t_x=a[x];
x_left=t_x.left;
t_k=a[x_left];
t_i.right=x;
t_i.left=t_x.left;
t_k.right=i;
t_x.left=i;
a[x]=t_x;
a[i]=t_i;
a[x_left]=t_k;
}
}
else//x的右边插入i
{
t=a[x];
if(t.right==0)//x的右边没有数
{
t_x.right=i;
t_i.left=x;
a[x]=t_x;
a[i]=t_i;
}
else//x的左边有数
{
int x_right;
t_x=a[x];
x_right=t_x.right;
t_k=a[x_right];
t_i.left=x;
t_i.right=t_x.right;
t_k.left=i;
t_x.right=i;
a[x]=t_x;
a[i]=t_i;
a[x_right]=t_k;
}
}
}
for(it=a.begin();it!=a.end();it++)//循环迭代打印各个数之间的关系
{
cout<<it->first<<" ";
cout<<"左边:";
cout<<it->second.left<<" ";
cout<<"右边:";
cout<<it->second.right<<endl;
}
input(a);//打印序列
return 0;
}
/*
4
1 0
2 1
1 0
2 3 4 1
*/
⑺ 如何在VC++6.0里进行C语言程序设计(十万火急!))
打开以后的操作步骤
new
->win32
console
application(在右边的location里面选要放的路径,在project
name里面写要起的工程名字)->OK->点Finish
新建了一个空的控制台应用程序的工程;
接下来添加C语言文件,
new->C++
source
file(在右边的file里面填写要建立的C语言文件名,注意要把扩展名写上,如建立的是main.c不要写main,否则系统默认的是C++文件);
建好以后就可以编写程序了
程序写好以后编译运行可以选择buile->excute
工程名.exe
没有错误的话可以运行出结果
有错误的话会给出相应的提示....
⑻ 如何使用c语言编写计算圆面积的程序
1、首先打开DEV C++软件,在编辑页面输入以下代码,如下图所示。
⑼ 帮我解释下这段C++代码,做火焰和熔浆效果的,
class CFireRoutine //烟火程序
{
public:
CFireRoutine(); //构造函数
virtual ~CFireRoutine(); //虚态的析构函数
// Functs (public)
void InitFire(); //初始化
void ClrHotSpots(); //清除燃烧点
void InitPallette(); //初始化调色板
void SetHotSpots(); //设置燃烧点
void MakeLines(); //生成扫描线
//渲染(视频内存,宽度,高度)
void Render(DWORD* pVideoMemory,
int iwidth,
int iheight);
//均值(在点x,y处)(像素均值?)
unsigned char Average(int x, int y);
// props
int m_iFlameHeight; //火焰高度
int m_iWidth; //宽度
int m_iHeight;//高度(应该是作图区高度)
//火焰来源,即从点火处的y坐标
int m_iFireSource;//The y position for the lit spots
int m_iFireChance; //燃烧几率
int m_iAvgFlameWidth; //火焰平均宽度
int m_iAlpha; //α(深度)
COLORREF m_FireColors[4]; //火焰颜色
BYTE* m_pFireBits; //火焰数据
DWORD m_pPalletteBuffer[256]; //调色板
long* m_pYIndexes; //颜色索引
};
//熔浆:
class CPlasmaRoutine
{
public:
CPlasmaRoutine();//构造函数
virtual ~CPlasmaRoutine();//虚态析构函数
// Methods
void SetDefaultValues(VARIANT* pExtParms);//设置缺省参数值(外部变量)
void InitializePlasma(VARIANT* pExtParms);//初始化岩浆参数
void Create(int iWidth,int iHeight);//按视图生成岩浆
void Render(DWORD* pBits, //按照像素位,视图宽度,高度,扫描线渲染
int iwidth,
int iheight,
int iLineLength);
//设置颜色索引的RGB值
void SetRGB(int iIndex,int R,int G,int B);
void InitCostBLTable(); //初始化损耗平衡表?BL是不是balance的意思啊?不知道,反正不是对比度和亮度,还是色彩饱和度?好像都不是
void InitPallette(); //初始化调色板
void CalcPlasma(); //计算岩浆
//按照颜色开始,颜色结束,颜色步长创建渐变色,存到buffer里面
void CreateGradient(COLORREF clrStart,COLORREF clrEnd,long lSteps,COLORREF* pBuffer);
// Props
int m_iWidth;//视图宽度
int m_iHeight;//视图高度
int m_iAlpha;//视图深度
BYTE* m_pPlasmaBits; //岩浆序列缓冲
DWORD m_pPalletteBuffer[256];//调色板
int m_icostbl[256];//损耗平衡表
COLORREF m_PlasmaColors[16];// Yep 16 colors needed to generate our pallete... 采用16种颜色产生调色板
//以下应该是曲线拟合用的贝塞尔曲线四个控制点和矢量坐标
unsigned char m_a1,m_a2,m_a3,m_a4,m_b1,m_b2,m_b3,m_b4;
int m_iModifier1;
int m_iModifier2;
int m_iModifier3;
int m_iModifier4;
//双方向修改器(两点拉拽形成的矢量)
int m_iXModifier1;
int m_iXModifier2;
int m_iYModifier1;
int m_iYModifier2;
};
// FireRoutine.cpp: implementation of the CFireRoutine class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FireRoutine.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction 构造函数,初始化所有参数,注意火源初始值为2,燃烧概率初始值为10
//////////////////////////////////////////////////////////////////////
CFireRoutine::CFireRoutine()
{
m_iWidth = 0;
m_iHeight = 0;
m_pFireBits = NULL;
m_pYIndexes = NULL;
m_iFireSource = 2;
m_iFireChance = 10;
m_iFlameHeight = 50;
m_iAlpha = 255;
m_FireColors[0] = RGB(0,0,0);// Black
m_FireColors[1] = RGB(255,0,0);// Red
m_FireColors[2] = RGB(255,255,0);// Yellow
m_FireColors[3] = RGB(255,255,255);// White
m_iAvgFlameWidth = 35;
}
//析构函数,如果颜色索引和渲染缓冲区存在则注销
CFireRoutine::~CFireRoutine()
{
if(m_pFireBits != NULL)
delete [] m_pFireBits;
if(m_pYIndexes != NULL)
delete [] m_pYIndexes;
m_pFireBits = NULL;
m_pYIndexes = NULL;
}
void CFireRoutine::InitFire()
{
// Get Rid of anything already there 初始化火焰,如果存在颜色索引和渲染缓冲则首先注销
if(m_pFireBits != NULL)
delete [] m_pFireBits;
if(m_pYIndexes != NULL)
delete [] m_pYIndexes;
// Add three to the height 高度自动加三
m_iHeight+=3;
m_pYIndexes = new long[m_iHeight]; //颜色索引时以火焰高度为长度的一个长整形数组
m_pFireBits = new BYTE[m_iWidth*m_iHeight]; //渲染缓冲区为一个W*H长度的字符型数组
// Clear the Fire bits 将火焰缓冲区置零
memset(m_pFireBits,0,(m_iWidth*m_iHeight));
// do all the y index pre-calc.. 在计算之前先将颜色缓冲值初始化为每个元素=宽度*高度
for (int y = m_iHeight; y >0; y--)
m_pYIndexes[y] = y * m_iWidth;
// Create our pallete
InitPallette(); //初始化调色板
ClrHotSpots(); //清除燃烧点
}
//所谓清除燃烧点就是将渲染缓冲区的某一行清零。哪一行呢?就是颜色索引中火源指向的那一行。
void CFireRoutine::ClrHotSpots()
{
// clear the fire line
memset(&m_pFireBits[m_pYIndexes[m_iFireSource]],0,m_iWidth);
}
//初始化调色板。您可能需要首先了解一下调色板的概念:虽然一个图可能是彩色的,但是每个像素如果
//都按照RGB三个字节方式存储,则成本太高了。调色板在于,假设这个图还是彩图,但是经过色彩分析,
//其中只有256种颜色是图中的常用颜色,这样一个字节就可以代表一个像素了,不过这个字节的值指的
//并不是RGB这种色彩矢量,而是256种颜色的代码,这256种颜色就是这幅图的调色板。
void CFireRoutine::InitPallette()
{
// Create a gradient between all the colors we have for our fire... 为我们的火焰创造一个过渡色使用的所有颜色
long iCount = 0;
COLORREF clrStart;
COLORREF clrEnd;
for(int iColor = 1;iColor<4;iColor++) //火焰的四个颜色定义
{
clrStart = m_FireColors[iColor-1]; //设置过渡色的起始颜色
clrEnd = m_FireColors[iColor]; //设置过渡色的终止颜色
int r, g, b; // First distance, then starting value 先计算距离,再计算值
float rStep, gStep, bStep; // Step size for each color //每种颜色的过渡步进值
// Get the color differences 取得三个颜色RGB的起始颜色和过渡颜色色差
r = (GetRValue(clrEnd) - GetRValue(clrStart));
g = (GetGValue(clrEnd) - GetGValue(clrStart));
b = (GetBValue(clrEnd) - GetBValue(clrStart));
int nSteps = max(abs(r), max(abs(g), abs(b))); //过渡步长数量取为RGB红绿蓝中色差最大者
float fStep = (float)(255/3)/ (float)nSteps; //将色差步长值转换为浮点数
// Calculate the step size for each color
rStep = r/(float)nSteps;//求得各颜色分量的色差步长值
gStep = g/(float)nSteps;
bStep = b/(float)nSteps;
// Reset the colors to the starting position 将颜色设置为渐进色初始颜色
r = GetRValue(clrStart);
g = GetGValue(clrStart);
b = GetBValue(clrStart);
for (int iOnBand = 0; iOnBand < nSteps; iOnBand++) //按照RGB计算出在渐变色全程中每个颜色的实际值
{
//COLORREF color = RGB(r+rStep*iOnBand, g + gStep*iOnBand, b + bStep *iOnBand);
COLORREF color = RGB(b + bStep *iOnBand, g + gStep*iOnBand,r+rStep*iOnBand);
long lIndex = (int)(iOnBand * fStep);
if(lIndex+((iColor-1)*85) < 255)
m_pPalletteBuffer[lIndex+((iColor-1)*85)] = color; //计算结果放到调色板里面去
}
}
// Step on the second color a little bit...向终止颜色过渡,以下颜色生成的内容与上面基本一致。
clrStart = m_FireColors[0];
clrEnd = m_FireColors[1];
for(int kj=0;kj<m_iFlameHeight;kj++)
m_pPalletteBuffer[kj] = 0;
int r, g, b; // First distance, then starting value
float rStep, gStep, bStep; // Step size for each color
// Get the color differences
r = (GetRValue(clrEnd) - GetRValue(clrStart));
g = (GetGValue(clrEnd) - GetGValue(clrStart));
b = (GetBValue(clrEnd) - GetBValue(clrStart));
int nSteps = max(abs(r), max(abs(g), abs(b)));
float fStep = (float)(85-m_iFlameHeight)/ (float)nSteps;
// Calculate the step size for each color
rStep = r/(float)nSteps;
gStep = g/(float)nSteps;
bStep = b/(float)nSteps;
// Reset the colors to the starting position
r = GetRValue(clrStart);
g = GetGValue(clrStart);
b = GetBValue(clrStart);
for (int iOnBand = 0; iOnBand < nSteps; iOnBand++)
{
//COLORREF color = RGB(r+rStep*iOnBand, g + gStep*iOnBand, b + bStep *iOnBand);
COLORREF color = RGB(b + bStep *iOnBand, g + gStep*iOnBand,r+rStep*iOnBand);
long lIndex = (int)(iOnBand * fStep);
m_pPalletteBuffer[lIndex+(85-m_iFlameHeight)] = color; //填写颜色值
}
}
// Macro to get a random integer within a specified range */ 这是一个按照范围取随机数的宏
#define getrandom( min, max ) (( rand() % (int)((( max ) + 1 ) - ( min ))) + ( min ))
#include <time.h>
void CFireRoutine::SetHotSpots() //设置燃烧点
{
ClrHotSpots(); //首先清除燃烧点
//m_iAvgFlameWidth
long lPosition = 0; //按照横轴位置进行累加,直到抵达宽度界限
while(lPosition < m_iWidth)
{
// see if we should do a flame
if (getrandom(0,100) < m_iFireChance) //得到一个随机数,看看是不是在燃烧概率范围内,如果不是就跳过去
{
// get a flame width
long lFlameWidth = getrandom(1,m_iAvgFlameWidth); //随机取得一个火焰宽度
for(int i=0;i<lFlameWidth;i++)
{
if(lPosition < m_iWidth) //如果位置在屏幕范围内,设置一个燃烧点
{
m_pFireBits[m_pYIndexes[m_iFireSource]+lPosition] =254;// set a hot spot!
lPosition++;
}
}
}
lPosition++;
}
// for (x = 0; x < m_iWidth; x++)
// {
// if (getrandom(0,100) < m_iFireChance)
// {
// }
// }
}
void CFireRoutine::MakeLines() //生成渲染扫描线
{
int x, y;
for (x = 0; x < m_iWidth; x++) //横向循环,从屏幕左侧到右侧
{
for (y = m_iFireSource; y<m_iHeight-1;y++) //纵向循环,从火源到火焰高度
// for (y = m_iHeight; y > m_iFireSource; y--)
{
//m_pFireBits[m_pYIndexes[y-1]+x] =Average(x,y);
m_pFireBits[m_pYIndexes[y+1]+x] =Average(x,y); //火焰值为扫描线均值
}
}
}
unsigned char CFireRoutine::Average(int x, int y)
{
unsigned char ave_color;
unsigned char ave1, ave2, ave3, ave4, ave5, ave6, ave7;
// Make sure we are not at the last line... 只要不是扫描线最后一样,平均值按照下列方式计算。
if(y == m_iHeight)
ave1 = m_pFireBits[m_pYIndexes[y-1] + x];
else
ave1 = m_pFireBits[m_pYIndexes[y + 1] + x];
//扫描线均值的方法,以x,y为中心,小半径为1,大半径为2的横向椭圆,从这个范围内取得颜色,然后求均值:
//基本上是下面这个图的样式:格式:取点编号(坐标)
/*
1#(x, y+1)
6#(x-2, y) 4#(x-1, y) 7#(x,y) 3#(x+1, y) 5#(x+2, y)
2#(x, y-1)
*/
ave2 = m_pFireBits[m_pYIndexes[y - 1] + x];
ave3 = m_pFireBits[m_pYIndexes[y] + x + 1];
ave4 = m_pFireBits[m_pYIndexes[y] + x - 1];
ave5 = m_pFireBits[m_pYIndexes[y] + x + 2];
ave6 = m_pFireBits[m_pYIndexes[y] + x - 2];
ave7 = m_pFireBits[m_pYIndexes[y] + x];
ave_color = (ave1 + ave2 + ave3 + ave4 + ave5 + ave6 + ave7) / 7;
//求出颜色均值并返回
return(ave_color);
}
//按照视频内存进行渲染
void CFireRoutine::Render(DWORD* pVideoMemory,
int iwidth,
int iheight
)
{
SetHotSpots(); // generate random hotspots 产生燃烧点
MakeLines(); // do all the math and screen updating //产生扫描线,更新屏幕
// Right now Im just going to blit it right onto the video memory //向视频内存做BitBlt缓冲拷贝
unsigned char* pSrcBitlin;// = m_pFireBits+(m_iWidth*3);// get rid of our fire source //获取火源
BYTE *dst;//=(BYTE*)Dib->pVideoMemory;
BYTE r;
BYTE g;
BYTE b;
for(int i=0;i<m_iHeight-3;i++) //逐行扫描
{
dst = (BYTE*)&pVideoMemory[(iwidth*i)]; //取得视频当前行
pSrcBitlin =&m_pFireBits[m_pYIndexes[i+3]]; //设置扫描线数据指针
for(int x=0;x<m_iWidth;x++)
{
//合成颜色,注意,是索引颜色取RGB分量后加上深度和饱和度,移位
r = GetRValue(m_pPalletteBuffer[pSrcBitlin[x]]);
g = GetGValue(m_pPalletteBuffer[pSrcBitlin[x]]);
b = GetBValue(m_pPalletteBuffer[pSrcBitlin[x]]);
dst[0]=(BYTE)(((r-dst[0])*m_iAlpha+(dst[0]<<8))>>8);
dst[1]=(BYTE)(((g-dst[1])*m_iAlpha+(dst[1]<<8))>>8);
dst[2]=(BYTE)(((b-dst[2])*m_iAlpha+(dst[2]<<8))>>8);
dst+=4;
}
}
}
关于岩浆和水波的源代码,概念差不多,都是首先建立颜色模型、然后匹配到缓冲中去,仔细对比一下就看懂了
⑽ 用C语言编写学生信息管理系统,十万火急!
可以参考
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}