虽然简单,但基本满足楼主要求了
//studenth
#include <iostream>
using namespace std;
#include <map>
#include <string>
class student
{
public:
void add(int nID);
void check(int nID);
void choose(int nID);
public:
map<int, string> studentInfo;
};
//studentcpp
#include "studenth"
void student::add(int nID)
{
cout<<"请输入添加的学号:"<<endl;
cin>>nID;
cout<<"请输入学生姓名:"<<endl;
string strName;
cin>>strName;
studentInfo[nID] = strName;
}
void student::check(int nID)
{
cout<<"请输入欲查询的学号:"<<endl;
cin>>nID;
if( studentInfofind(nID) != studentInfoend())
{
cout<<"该学号学生姓名为:"<<studentInfo[nID]<<endl;
}
else
{
cout<<"该学号不存在!";
}
}
#include "studenth"
#include <iostream>
using namespace std;
void main()
{
student st;
stchoose(0);
}
#include <stdioh>
#include <stdlibh>
#include <timeh>
void Init(int a[],int n); //随机生成元素取值范围在0到99的数组
void Short(int p,int n); //用选择法对数组中的元素从小到大排序
void Print(int p,int n); //在屏幕上输出数组各元素的值(逗号分隔)
#define N (10)
int main()
{
int a[N],b[N],c[N2],i;
srand(time(NULL));
Init(a,N);
Print(a,N);
Short(a,N);
Print(a,N);
Init(b,N);
Print(b,N);
Short(b,N);
Print(b,N);
for(i=0;i<N;++i)
{
c[i]=a[i];
}
for(i=0;i<N;++i)
{
c[i+N]=b[i];
}
Print(c,2N);
Short(c,2N);
Print(c,2N);
return 0;
}
void Init(int a[],int n)
{
int i;
for(i=0;i<n;++i)
{
a++=rand()%100;
}
}
void Short(int p,int n)
{
int i,j,t;
for(i=0;i<n-1;++i)
{
for(j=0;j<n-i-1;++j)
{
if(p[j]>p[j+1])
{
t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
}
void Print(int p,int n)
{
int i;
for(i=0;i<n;++i)
{
printf("%d%c",p++,i<n-1',':'\n');
}
}
属于并行编程的问题,C语言本身并不具备并行计算能力,可以通过系统API调用实现。编写一个调度程序,然后通过这个调度程序调度你的小程序占用某个核心,你的小程序本身不能决定自己占用哪个核心。
#include<stdioh>
#include<mathh>
int main()
{
double x,s,up,each,abs;
int a,n,i;
s=0;
do {
scanf("%lf",&x);
} while ( x== 0 ); //-x不能为0
for(n=1;;n++)
{
up=(double)pow(x,n); //-n不需要加(int)
a=i=1; //每次都应该重新赋初值!!关键错误
do
{
a=i;
i++;
}while(i<=n);
each=up/a;
if(n%2==0)
{
s=s-each;
}
else
{
s=s+each;
}
///////////////没有说x一定是大于0的,x小于0时,就不同了,所以要判断each的符号
if ( each < 0 )
abs=-each;
else
abs=each;
///////////////
if(abs<1e-5) break; //移动到这里来检查
}
printf("sum=%2lf\n",s);
return 0;
}
#include<stdioh>
void main()
{
int x,y;
x=y=0;
while(x<15)
{
y++,x+=++y;
printf("%d,%d\n",y,x);
}
printf("%d,%d",y,x);
}
2,2
4,6
6,12
8,20
8,20Press any key to continue上面是运行结果,执行一次while中的语句,y值增加2,x加上的值是y增加2后的值
以上就是关于用C语言帮我编一个小程序(大一作业)全部的内容,包括:用C语言帮我编一个小程序(大一作业)、求c语言大佬帮助!帮我写个小程序,谢谢、如何写一个大量占用CPU资源和内存资源的小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)