导航:首页 > 源码编译 > 课程设计源码是什么

课程设计源码是什么

发布时间:2023-06-01 11:53:52

java课程设计源代码(急!!!!)

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

public class game21 extends JFrame {
private JLabel label_2;
private int number;
private int sum;
final JLabel label = new JLabel();
final JLabel label_1 = new JLabel();

public static void main(String[] args) {
new game21();
}

public game21() {
super("21点?!");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
onClick();
}
});
button.setText("出牌");
button.setBounds(170, 350, 106, 28);
getContentPane().add(button);
label.setBorder(new LineBorder(Color.black, 1, false));
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("", Font.BOLD, 26));
label.setText("背面");
label.setBounds(158, 81, 137, 153);
getContentPane().add(label);

label_1.setText("你已经拥有的牌:");
label_1.setBounds(109, 22, 270, 45);
getContentPane().add(label_1);
this.setBounds(200, 300, 501, 528);
this.setVisible(true);
getContentPane().add(getLabel_2());
}

public int randNumber() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * 10 + 1);
}

public void onClick() {
number = this.randNumber();
this.sum += number;
label.setText("" + number);
String strTemp = this.label_1.getText();
strTemp += "" + number + " ";
label_1.setText(strTemp);
String temp = "合计:" + sum;
label_2.setText(temp);
isWin();
}

public void isWin() {
if (sum > 21) {
JOptionPane.showMessageDialog(this, "你输了");
clear();
return;
} else if (sum == 21) {
JOptionPane.showMessageDialog(this, "你赢了");
clear();
return;
} else {
int i = JOptionPane.showOptionDialog(this, "是否继续?", "提示",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (i == JOptionPane.OK_OPTION) {
onClick();
} else
return;
}
}

private void clear() {
label_2.setText("合计:");
sum = 0;
number = 0;
label_1.setText("你已经拥有的牌:");
}

/**
* @return
*/
protected JLabel getLabel_2() {
if (label_2 == null) {
label_2 = new JLabel();
label_2.setText("合计:");
label_2.setBounds(313, 35, 66, 18);
}
return label_2;
}

}
真好无聊中。。

㈡ 高分求C语言课程设计源代码(分不多了,全部给你们)

#include <string>
#include <iostream>
#include <time.h>
#include <vector>
using namespace std;
class Employee //定义雇员类
{
public:
Employee(); //构造函数
virtual VEmployee();
virtual void Display()=0;
int GetAge(); //获取年龄
string GetName(); //获取姓名
protected:
int Id; //职工ID号
string Name; //职工姓名
char Sex[5]; //性别
int Wage; //工资
string BirthDay; //出身年月
string WorkTime; //参加工作时间
int Age; //年龄
};
class Worker : public Employee //定义工人类
{
public:
Worker();
virtual VWorker();
void Display();

};
class Teacher : public Employee //定义教师类
{
public:
Teacher();
virtual VTeacher();
void Display();
string GetAcademy();
private:
string Academy;
};

Employee::Employee()
{

}

Employee::VEmployee()
{

}

int Employee::GetAge()
{
return Age;
}

string Employee::GetName()
{
return Name;
}
Teacher::Teacher() //添加教师信息
{
cout<<"请输入该教师的信息:"<<endl;

cout<<"职工编号 : "<<endl;
cin>>Id;

cout<<"姓名 : "<<endl;
cin>>Name;

cout<<"性别 : "<<endl;
cin>>Sex;

cout<<"工资 : "<<endl;
cin>>Wage;

cout<<"出生时间 : (格式xxxx/xx/xx)"<<endl;
cin>>BirthDay;

cout<<"参加工作时间 : (格式xxxx/xx/xx)"<<endl;
cin>>WorkTime;

cout<<"所属院系 : "<<endl;
cin>>Academy;

//从生日里提取出生的年份
int Pos = BirthDay.find_first_of('/');
string BirthYear;
BirthYear.assign(BirthDay,0,Pos);
char chBirthYear[6];
strcpy(chBirthYear,BirthDay.c_str());
//获取当前系统的年份
char NowYear[5];
time_t tnow = time(0);
strftime(NowYear , 5 , "%Y" , localtime(&tnow));
Age = atoi(NowYear)-atoi(chBirthYear); //计算年龄

}

Teacher::VTeacher()
{

}

void Teacher::Display(){ //display()同名函数,输出教师信息
cout<<"职工编号 : "<<Id<<endl;
cout<<"姓名 : "<<Name<<endl;
cout<<"性别 : "<<Sex<<endl;
cout<<"工资 : "<<Wage<<endl;
cout<<"出生时间 : "<<BirthDay<<endl;
cout<<"参加工作时间 : "<<WorkTime<<endl;
cout<<"年龄 : "<<Age<<endl;
}

string Teacher::GetAcademy(){
return Academy;
}
Worker::Worker() //添加工人信息
{
cout<<"请输入该工人的信息:"<<endl;
cout<<"职工编号 : "<<endl;
cin>>Id;

cout<<"姓名 : "<<endl;
cin>>Name;

cout<<"性别 : "<<endl;
cin>>Sex;

cout<<"工资 : "<<endl;
cin>>Wage;

cout<<"出生时间 : (格式xxxx/xx/xx)"<<endl;

cin>>BirthDay;
cout<<"参加工作时间 : (格式xxxx/xx/xx)"<<endl;
cin>>WorkTime;

//从生日里提取出生的年份
int Pos = BirthDay.find_first_of('/');
string BirthYear;
BirthYear.assign(BirthDay,0,Pos);
char chBirthYear[6];
strcpy(chBirthYear,BirthDay.c_str());
//获取当前系统的年份
char NowYear[5];
time_t tnow = time(0);
strftime(NowYear , 5 , "%Y" , localtime(&tnow));
Age = atoi(NowYear)-atoi(chBirthYear); //计算年龄
}

Worker::VWorker()
{

}

void Worker::Display(){//display()同名函数,输出工人信息
cout<<"职工编号 : "<<Id<<endl;
cout<<"姓名 : "<<Name<<endl;
cout<<"性别 : "<<Sex<<endl;
cout<<"工资 : "<<Wage<<endl;
cout<<"出生时间 : "<<BirthDay<<endl;
cout<<"参加工作时间 : "<<WorkTime<<endl;
cout<<"年龄 : "<<Age<<endl;
}

void AddTeacher(vector <Teacher> *TeaInfo) //新增老师对象
{
system("color 05A"); //设置当前窗口的背景色和前景色
Teacher TeaTemp;
(*TeaInfo).push_back(TeaTemp);
}

void AddWoker(vector <Worker> *WorkerInfo) //新增工人对象
{
system("color 05A");
Worker Wokertmp;
(*WorkerInfo).push_back(Wokertmp);
}

void DisplayAll(vector <Teacher> *TeaInfo,vector <Worker> *WokerInfo){ //显示全部职工记录
system("color 05A");
cout<<"所有教师的信息:"<<endl;
vector <Teacher>::iterator pTeaInfo;
for (pTeaInfo=(*TeaInfo).begin();(*TeaInfo).empty()!=1&&pTeaInfo!=(*TeaInfo).end();pTeaInfo++) //如果到达vector末尾,则退出
{
(*pTeaInfo).Display();
cout<<endl;
}

cout<<"所有工人的信息:"<<endl;
vector <Worker>::iterator pWorkerInfo;
for (pWorkerInfo=(*WokerInfo).begin();(*WokerInfo).empty()!=1&&pWorkerInfo!=(*WokerInfo).end();pWorkerInfo++) //如果到达vector末尾,则退出
{
(*pWorkerInfo).Display();
cout<<endl;
}
cout<<"按Enter返回"<<endl;
getchar(); getchar();
}

void DisAvgTeacherAge(vector <Teacher> *TeaInfo){ //查询老师平均年龄
system("color 05A");
int SumAge = 0;
vector <Teacher>::iterator pTeaInfo;
for (pTeaInfo=(*TeaInfo).begin();(*TeaInfo).empty()!=1&&pTeaInfo!=(*TeaInfo).end();pTeaInfo++)//遍历老师容器
{ //如果到达vector末尾,则退出
SumAge+= (*pTeaInfo).GetAge();
cout<<endl;
}
if((*TeaInfo).size()!=0)
cout<<"教师的平均年龄为"<<SumAge/((*TeaInfo).size())<<endl;
else cout<<"没有记录"<<endl;
cout<<"按Enter返回"<<endl;
getchar(); getchar();
}

void DisAvgWorkerAge(vector <Worker> *WokerInfo){
system("color 05A");
int SumAge = 0;
vector <Worker>::iterator pWorkerInfo;
for (pWorkerInfo=(*WokerInfo).begin();(*WokerInfo).empty()!=1&&pWorkerInfo!=(*WokerInfo).end();pWorkerInfo++) //如果到达vector末尾,则退出
{
SumAge+= (*pWorkerInfo).GetAge();
cout<<endl;
}

if((*WokerInfo).size()!=0)
cout<<"职工的平均年龄为"<<SumAge/((*WokerInfo).size())<<endl;
else cout<<"没有记录"<<endl;
cout<<"按Enter键返回"<<endl;
getchar(); getchar();
}

void DelTeacher(vector <Teacher> *TeaInfo){ //用于删除老师信息

system("color 05A");
bool Hflag=false;
string SearchName;
vector <Teacher>::iterator pTeaInfo;

cout<<"请输入您要删除的老师的姓名:"<<endl;
cout<<"姓名: ";
cin>>SearchName;
for(pTeaInfo=(*TeaInfo).begin();(*TeaInfo).empty() != 1&&pTeaInfo!=(*TeaInfo).end();pTeaInfo++) //如果到达vector末尾,则退出
{

if (0==SearchName.compare((*pTeaInfo).GetName())) //如果找到要删除老师的姓名,则执行
{
Hflag=true; //找到老师
(*TeaInfo).erase(pTeaInfo); //删除vector中指定的老师
continue;
}
}
if (false==Hflag) //如果没有该老师,则执行
{
cout<<"没有该老师!"<<endl;
}
cout<<"按Enter返回"<<endl;
getchar(); getchar();
}

void DelWorker(vector <Worker> *WokerInfo) //用于删除工人信息
{
system("color 05A");
bool Hflag=false;
string SearchName;
vector <Worker>::iterator pWorkerInfo;

cout<<"请输入您要删除的工人的姓名:"<<endl;
cout<<"姓名: ";
cin>>SearchName;
for(pWorkerInfo=(*WokerInfo).begin();(*WokerInfo).empty() != 1&&pWorkerInfo!=(*WokerInfo).end();pWorkerInfo++) //如果到达vector末尾,则退出
{

if (0==SearchName.compare((*pWorkerInfo).GetName())) //如果找到要删除工人的姓名,则执行
{
Hflag=true; //找到工人
(*WokerInfo).erase(pWorkerInfo); //删除vector中指定的工人
continue;
}
}
if (false==Hflag) //如果没有该工人,则执行
{
cout<<"没有该老师!"<<endl;
}
cout<<"按Enter返回"<<endl;
getchar();getchar();

}

void SearchByName(vector <Teacher> *TeaInfo,vector <Worker> *WokerInfo){ //按名字查找职工信息
system("color 05A");
bool Hflag=false;
string SearchName;
vector <Teacher>::iterator pTeaInfo;

cout<<"请输入您要查找的职工的姓名:"<<endl;
cout<<"姓名: ";
cin>>SearchName;
for(pTeaInfo=(*TeaInfo).begin();pTeaInfo!=(*TeaInfo).end();pTeaInfo++)
{

if (0==SearchName.compare((*pTeaInfo).GetName())) //如果找到输入的职工,则执行
{
Hflag=true; //找到职工
cout<<"这个人是老师,他的信息为:"<<endl;
(*pTeaInfo).Display(); //显示职工信息
continue;
}
}

vector <Worker>::iterator pWorkerInfo;
for(pWorkerInfo=(*WokerInfo).begin();pWorkerInfo!=(*WokerInfo).end();pWorkerInfo++)
{

if (0==SearchName.compare((*pWorkerInfo).GetName())) //如果找到输入的职工,则执行
{
Hflag=true; //找到职工
cout<<"这个人是老师,个人信息为:"<<endl;
(*pWorkerInfo).Display(); //显示职工信息
continue;
}
}
if (false==Hflag)
{
cout<<"没有这个职工!"<<endl; //没有找到信息
}

cout<<"按Enter返回"<<endl; //返回
getchar(); getchar();
}

void DisTeacherByAcademy(vector <Teacher> TeaInfo){ //按系输出教师信息
system("color 05A");
bool Hflag=false;
string SearchName;
vector <Teacher>::iterator pTeaInfo;

while((TeaInfo).empty()!=1) { //输出所有指定系的老师
pTeaInfo=(TeaInfo).begin();
string Academy = (*pTeaInfo).GetAcademy();
cout<<"系:"<<Academy<<","<<"该系的老师有:"<<endl;
for(pTeaInfo=(TeaInfo).begin();(TeaInfo).empty()!=1&&pTeaInfo!=(TeaInfo).end();){
if (0==Academy.compare((*pTeaInfo).GetAcademy()))
{
(*pTeaInfo).Display();
cout<<endl;
(TeaInfo).erase(pTeaInfo);
pTeaInfo=(TeaInfo).begin();
}
else pTeaInfo++;
}
cout<<endl;
}
cout<<"按Enter返回"<<endl;
getchar(); getchar();
}

void WriteFile(vector <Teacher> *TeaInfo,vector <Worker> *WokerInfo) //生成新文件
{

FILE *fp;
if (NULL==(fp=fopen("Employee.txt","w+")))
{
cout<<"打开文件错误"<<endl;
exit(-1);
}

vector <Worker>::iterator pWorkerInfo;
vector <Teacher>::iterator pTeaInfo;
for(pTeaInfo=(*TeaInfo).begin();pTeaInfo!=(*TeaInfo).end();pTeaInfo++) //写入vector中所有老师的信息
{
fputs("教师信息:\n",fp);
fprintf(fp,"姓名:%s\n",(*pTeaInfo).GetName().c_str());
fprintf(fp,"年龄:%d\n",(*pTeaInfo).GetAge());
fputs("\n",fp);
}
fputs("教师信息结束\n",fp);
for(pWorkerInfo=(*WokerInfo).begin();pWorkerInfo!=(*WokerInfo).end();pWorkerInfo++) //写入vector中所有老师的信息
{
fputs("职工信息:\n",fp);
fprintf(fp,"姓名:%s\n",(*pWorkerInfo).GetName().c_str());
fprintf(fp,"年龄:%d\n",(*pWorkerInfo).GetAge());
fputs("\n",fp);
}
fputs("职工信息结束\n",fp);
fclose(fp);
}

void Mainmenu(){//菜单界面
system("color 05A"); //设置当前窗口的背景色和前景色
cout<<" ╭――――――――――《教职工管理系统》―――――――――╮"<<endl;
cout<<" ∣ 请选择功能 ∣"<<endl;
cout<<" ├――――――――――――――――――――――――――――┤"<<endl;
cout<<" ∣ 1.新建并输入职工数据 ∣"<<endl;
cout<<" ∣ 2.按条件输出职工数据 ∣"<<endl;
cout<<" ∣ 3.删除职工数据 ∣"<<endl;
cout<<" ∣ 0.退出 ∣"<<endl;
cout<<" ╰――――――――――――――――――――――――――――╯"<<endl;
cout<<" ――――――――――――――――――――――――――――――"<<endl;
cout<<" 请选择您要服务的类别: " ;

}

void Insert(vector <Teacher> *TeaInfo,vector <Worker> *WorkerInfo) //增加职工数据菜单界面
{
system("color 05A"); //设置当前窗口的背景色和前景色
int select = -1;
while(select!=0)
{
cout<<" ╭――――――――――《增加职工数据》――――――――――╮"<<endl;
cout<<" ∣ 请选择操作: ∣"<<endl;
cout<<" ├――――――――――――――――――――――――――――┤"<<endl;
cout<<" ∣ 1增加一位教师记录 ∣"<<endl;
cout<<" ∣ 2增加一位工人记录 ∣"<<endl;
cout<<" ∣ 0返回主菜单 ∣"<<endl;
cout<<" ╰――――――――――――――――――――――――――――╯"<<endl;
cin>>select;
switch(select){
case 1:AddTeacher(TeaInfo);break;
case 2:AddWoker(WorkerInfo);break;
case 3:Mainmenu();break;
default:
cout<<"回到主菜单!"<<endl;
}

}
}
void Search(vector <Teacher> *TeaInfo,vector <Worker> *WorkerInfo) //查询职工数据菜单界面
{
system("color 05A"); //设置当前窗口的背景色和前景色
int select = -1;
while(select!=0)
{
cout<<" ╭――――――――――《查询职工数据》――――――――――╮"<<endl;
cout<<" ∣ 请选择操作: ∣"<<endl;
cout<<" ├――――――――――――――――――――――――――――┤"<<endl;
cout<<" ∣ 1显示全部职工记录 ∣"<<endl;
cout<<" ∣ 2按系输出教师信息 ∣"<<endl;
cout<<" ∣ 3按姓名检索所有信息 ∣"<<endl;
cout<<" ∣ 4计算教师平均年龄 ∣"<<endl;
cout<<" ∣ 5计算工人平均年龄 ∣"<<endl;
cout<<" ∣ 0返回主菜单 ∣"<<endl;
cout<<" ╰――――――――――――――――――――――――――――╯"<<endl;
cin>>select;
switch(select){
case 1:DisplayAll(TeaInfo,WorkerInfo);break;
case 2:DisTeacherByAcademy(*TeaInfo);break;
case 3:SearchByName(TeaInfo,WorkerInfo);break;
case 4:DisAvgTeacherAge(TeaInfo);break;
case 5:DisAvgWorkerAge(WorkerInfo);break;
case 6:Mainmenu();break;
default:
cout<<"回到主菜单!"<<endl;
}
}
}
void Delete(vector <Teacher> *TeaInfo,vector <Worker> *WorkerInfo) //删除职工数据
{
system("color 05A"); //设置当前窗口的背景色和前景色
int select = -1;
while(select!=0)
{
cout<<" ╭――――――――――《删除职工数据》――――――――――╮"<<endl;
cout<<" ∣ 请选择操作: ∣"<<endl;
cout<<" ├――――――――――――――――――――――――――――┤"<<endl;
cout<<" ∣ 1删除一位教师记录 ∣"<<endl;
cout<<" ∣ 2删除一位工人记录 ∣"<<endl;
cout<<" ∣ 0返回主菜单 ∣"<<endl;
cout<<" ╰――――――――――――――――――――――――――――╯"<<endl;
cin>>select;
switch(select){
case 1:DelTeacher(TeaInfo);break;
case 2:DelWorker(WorkerInfo);break;
case 3:Mainmenu();break;
default:
cout<<"回到主菜单!"<<endl;
}
}
}

void MainCho(vector <Teacher> *TeaInfo,vector <Worker> *WorkerInfo)
{ //主菜单操作
int choice = -1;
while(choice!=0){
Mainmenu();
cin>>choice;
switch(choice){
case 1:Insert(TeaInfo,WorkerInfo);break;
case 2:Search(TeaInfo,WorkerInfo);break;
case 3:Delete(TeaInfo,WorkerInfo);break;
case 0:break;
default:
cout<<"操作错误!"<<endl;
}
}
}
void main() //主函数
{
vector <Teacher> TeaInfo; //
vector <Worker> WorkerInfo; //
vector <Teacher>::iterator pTeacher; //
vector <Worker>::iterator pWoker; //
pTeacher = TeaInfo.begin(); //
pWoker = WorkerInfo.begin(); //
MainCho(&TeaInfo,&WorkerInfo); //调用主要处理程序
WriteFile(&TeaInfo,&WorkerInfo); //存入文件操作

}

㈢ 网络课程设计源代码:慢开始和拥塞控制算法

TCP采用慢开始和拥塞避免的方法控制发送
慢开始的思路是,先测试一下,在由小到大的增大发送窗口
具体的:预先设置一个慢开始门限,ssthresh(用于控制拥塞)
先设拥塞窗口cwnd=1,发送第一个报文,收到确认后把cwnd设为2,在发送,收到回复后,再把cwnd增加2个,即,收到回复后就把cwnd增加一倍,这就是慢开始算法
当cwnd>ssthresh就停止上述的慢开始算法而使用拥塞避免算法
拥塞避免算法就是每收到一个回复后就把cwnd加1,直到出现拥塞
无论在慢开始还是拥塞避免时只要出现拥塞就把ssthresh设为原值的一半(这就是乘法减小)并把cwnd设为1,在执行慢开始算法,重复上述过程

㈣ 求C语言课程设计源代码 急~!!

#include "stdio.h"
#define MAX 100 /*定义输入数据的最大长度*/

void countmax(int a[MAX],int N){ /*计算最值的函数*/
int minn=a[0],maxx=a[0]; /*minn表最小值,maxx表最大值*/
for(int i=0;i<=N;i++){ /*N是实际输入数组的长度*/
if(a[i]<minn) /*循环求最值*/
minn=a[i];
else
if(a[i]>maxx)
maxx=a[i];
}
printf("\n最小值:%d\n最大值:%d\n",minn,maxx);
printf("\n————————————————————————\n");
}

void found(int a[MAX],int N){ /*查找函数*/
int Flag = 1,x; /*Flag用来标记是否查找成功,0表成功,1表未成功*/
printf("请输入你要查找的数: ");
scanf("%d",&x); /*x是待查找的数*/
for(int i=0;i<=N;i++){
if(a[i]==x){
printf("所找的数在数组中的位置是第 %d 位\n",i+1);
Flag = 0;
break;
}
}
if(Flag == 1)
printf("Not Found!\n");
printf("————————————————————————\n");
}

void deletedata(int a[MAX],int N){ /*删除操作函数*/
int Flag = 1,x,pos; /*Flag用来标记是否删除成功,0表成功,1表未成功,pos用来记录删除的位置*/
printf("请输入你要删除的数: ");
scanf("%d",&x);
for(int i = 0;i <= N;i++){ /*在数组中循环查找所要删除的数*/
if(a[i]==x){
for(int j=i;j<=N;j++) /*删除位置后的数全部向前移动一位*/
a[j]=a[j+1];
Flag = 0;
N--; /*数组长度减1*/
pos = i; /*记录删除位置*/
break;
}
}
if(Flag==1)
printf("Not Found!");
else{
printf("删除成功!\n");
printf("所删除的数在数组中的位置是第 %d 位\n",pos+1);
}
printf("删除操作后的数据为:\n");
for(int j=0;j<=N;j++)
printf("%d ",a[j]);
printf("\n————————————————————————\n");
}

void sumdata(int a[MAX],int N){ /*求奇数和偶数函数*/
int SUM1=0,SUM2=0,N1=0,N2=0;
/*SUM1表示偶数之和,N1表偶数个数
**SUM2表示奇数之和,N2表奇数个数
*/
for(int i=0;i<=N;i++){
if(a[i]%2==0){
N1++;
SUM1 = SUM1 + a[i];
}
else{
N2++;
SUM2 = SUM2 + a[i];
}

}
printf("数据中的偶数个数为: %d 个,平均值为: %d\n",N1,SUM1/N1);
printf("数据中的奇数个数为: %d 个,平均值为: %d\n",N2,SUM2/N2);
printf("————————————————————————\n");
}

int main(){

int i=0,k,N,a[MAX],data;
/*k用来标记所选择的操作,data表示输入的数据,a数组用来存储输入的数据*/
printf("请输入数据:\n");
scanf("%d",&data);
while(data!=0){
a[i]=data;
scanf("%d",&data);
N=i++;
}
printf("\n您输入了%d个数据,如下所示:\n",N+1);
for(i=0;i<=N;i++)
printf("%d ",a[i]);

printf("\n————————————————————————");
printf("\n\n请选择下面的一个项目:\n");
printf("1、求最值\n2、查找\n3、删除\n4、统计及平均\n5、退出\n");
printf("————————————————————————\n");
scanf("%d",&k);
switch(k){
case 1:
countmax(a,N);
break;
case 2:
found(a,N);
break;
case 3:
deletedata(a,N);
break;
case 4:
sumdata(a,N);
break;
case 5:
break;
default:
break;
}
return 0;
}

㈤ 求数据结构课程设计。。安排教学计划的源代码。。

#include<string.h>
#include<ctype.h>
#include<malloc.h> // malloc()等
#include<limits.h> // INT_MAX等
#include<stdio.h> // EOF(=^Z或F6),NULL
#include<stdlib.h> // atoi()52
#include<io.h> // eof()
#include<math.h> // floor(),ceil(),abs()
#include<process.h> // exit()
#include<iostream.h> // cout,cin
// 函数结果状态代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等
typedef int Boolean; // Boolean是布尔类型,其值是TRUE或FALSE
#define MAX_NAME 10
/* 顶点字符串的最大长度 */
#define MAXCLASS 100
int Z=0;
int X=0;
int xqzs,q=1,xfsx;
typedef int InfoType;
typedef char VertexType[MAX_NAME]; /* 字符串类型 */
/* 图的邻接表存储表示 */
#define MAX_VERTEX_NUM 100
typedef enum{DG}GraphKind; /* {有向图,有向网,无向图,无向网} */
typedef struct ArcNode
{
int adjvex; /* 该弧所指向的顶点的位置 */
struct ArcNode *nextarc; /* 指向下一条弧的指针 */
InfoType *info; /* 网的权值指针) */
}ArcNode; /* 表结点 */
typedef struct
{
VertexType data; /* 顶点信息 */
ArcNode *firstarc; /* 第一个表结点的地址,指向第一条依附该顶点的弧的指针 */
}VNode,AdjList[MAX_VERTEX_NUM]; /* 头结点 */
typedef struct
{
AdjList vertices,verticestwo;
int vexnum,arcnum; /* 图的当前顶点数和弧数 */
int kind; /* 图的种类标志 */
}ALGraph;
/* 图的邻接表存储的基本操作 */
int LocateVex(ALGraph G,VertexType u)
{ /* 初始条件: 图G存在,u和G中顶点有相同特征 */
/* 操作结果: 若G中存在顶点u,则返回该顶点在图中位置;否则返回-1*/
int i;
for(i=0;i<G.vexnum;++i)
if(strcmp(u,G.vertices[i].data)==0)
return i;
return -1;
}
Status CreateGraph(ALGraph *G)
{ /* 采用邻接表存储结构,构造没有相关信息的图G(用一个函数构造4种图) */
int i,j,k;
VertexType va,vb;
ArcNode *p;

printf("请输入教学计划的课程数: ");
scanf("%d",&(*G).vexnum);
printf("请输入拓扑排序所形成的课程先修关系的边数:");
scanf("%d",&(*G).arcnum);
printf("请输入%d个课程的代表值(<%d个字符):\n",(*G).vexnum,MAX_NAME);
for(i=0;i<(*G).vexnum;++i) /* 构造顶点向量 */
{ scanf("%s",(*G).vertices[i].data);
(*G).vertices[i].firstarc=NULL;
}
printf("请输入%d个课程的学分值(<%d个字符):\n",(*G).vexnum,MAX_NAME);
for(i=0;i<(*G).vexnum;++i) /* 构造顶点向量 */
{scanf("%s",(*G).verticestwo[i].data);
}
printf("请顺序输入每条弧(边)的弧尾和弧头(以空格作为间隔):\n");
for(k=0;k<(*G).arcnum;++k) /* 构造表结点链表*/
{ scanf("%s%s",va,vb);
i=LocateVex(*G,va); /* 弧尾 */
j=LocateVex(*G,vb); /* 弧头 */
p=(ArcNode*)malloc(sizeof(ArcNode));
p->adjvex=j;
p->info=NULL; /* 图 */
p->nextarc=(*G).vertices[i].firstarc; /* 插在表头 */
(*G).vertices[i].firstarc=p;
}
return OK;
}
void Display(ALGraph G)
{ /* 输出图的邻接矩阵G */
int i;
ArcNode *p;
switch(G.kind)
{case DG: printf("有向图\n");
}
printf("%d个顶点:\n",G.vexnum);
for(i=0;i<G.vexnum;++i)
printf("%s ",G.vertices[i].data);
printf("\n%d条弧(边):\n",G.arcnum);
for(i=0;i<G.vexnum;i++)
{
p=G.vertices[i].firstarc;
while(p)
{printf("%s→%s ",G.vertices[i].data,G.vertices[p->adjvex].data);
p=p->nextarc;
}
printf("\n");
}
}
void FindInDegree(ALGraph G,int indegree[])
{ /* 求顶点的入度,算法调用 */
int i;
ArcNode *p;
for(i=0;i<G.vexnum;i++)
indegree[i]=0; /* 赋初值 */
for(i=0;i<G.vexnum;i++)
{
p=G.vertices[i].firstarc;
while(p)
{ indegree[p->adjvex]++;
p=p->nextarc;
}
}
}
typedef int SElemType; /* 栈类型 */
/*栈的顺序存储表示 */
#define STACK_INIT_SIZE10 /* 存储空间初始分配量 */
#define STACKINCREMENT 2 /* 存储空间分配增量 */
typedef struct SqStack
{
SElemType *base; /* 在栈构造之前和销毁之后,base的值为NULL */
SElemType *top; /* 栈顶指针 */
int stacksize; /* 当前已分配的存储空间,以元素为单位 */
}SqStack; /* 顺序栈 */
/* 顺序栈的基本操作 */
Status InitStack(SqStack *S)
{ /* 构造一个空栈S */
(*S).base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(!(*S).base)
exit(OVERFLOW); /* 存储分配失败 */
(*S).top=(*S).base;
(*S).stacksize=STACK_INIT_SIZE;
return OK;
}
Status StackEmpty(SqStack S)
{ /* 若栈S为空栈,则返回TRUE,否则返回FALSE */
if(S.top==S.base)
return TRUE;
else
return FALSE;
}
Status Pop(SqStack *S,SElemType *e)
{ /* 若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR */
if((*S).top==(*S).base)
return ERROR;
*e=*--(*S).top;
return OK;
}
Status Push(SqStack *S,SElemType e)
{ /* 插入元素e为新的栈顶元素 */
if((*S).top-(*S).base>=(*S).stacksize) /* 栈满,追加存储空间 */
{
(*S).base=(SElemType*)realloc((*S).base,((*S).stacksize+STACKINCREMENT)*sizeof
(SElemType));
if(!(*S).base)
exit(OVERFLOW); /* 存储分配失败 */
(*S).top=(*S).base+(*S).stacksize;
(*S).stacksize+=STACKINCREMENT;
}
*((*S).top)++=e;
return OK;
}
typedef int pathone[MAXCLASS];
typedef int pathtwo[MAXCLASS];
Status TopologicalSort(ALGraph G)
{ /* 有向图G采用邻接表存储结构。若G无回路,则输出G的顶点的一个拓扑序列并返回OK,*/
/* 否则返回ERROR。 */
int i,k,j=0,count,indegree[MAX_VERTEX_NUM];
SqStack S;
pathone a;
pathtwo b;
ArcNode *p;
FindInDegree(G,indegree); /* 对各顶点求入度indegree[0..vernum-1]*/
InitStack(&S); /* 初始化栈 */
for(i=0;i<G.vexnum;++i) /* 建零入度顶点栈S */
if(!indegree[i])
Push(&S,i); /* 入度为0者进栈 */
count=0; /* 对输出顶点计数 */
while(!StackEmpty(S))
{ /* 栈不空 */
Pop(&S,&i);
a[i]=*G.vertices[i].data;
b[i]=*G.verticestwo[i].data;
printf("课程%s→学分%s ",G.vertices[i].data,G.verticestwo[i].data);
/* 输出i号顶点并计数 */
++count;
for(p=G.vertices[i].firstarc;p;p=p->nextarc)
{ /* 对i号顶点的每个邻接点的入度减1 */
k=p->adjvex;
if(!(--indegree[k])) /* 若入度减为0,则入栈 */
Push(&S,k);
}
}
if(count<G.vexnum)
{printf("此有向图有回路\n");
return ERROR;
}
else
{printf("为一个拓扑序列。\n");
}
while(q<=xqzs)
{ int C=0;
if(X<=G.arcnum)
{ while(C<=xfsx)
{C+=*G.verticestwo[Z].data;
++Z;
}
printf("第%d个学期应学课程:",q);
while(X<=Z)
{cout<<*G.vertices[X].data<<"";
++X;
}
cout<<endl;
q++;
}
else
{cout<<"课程编制已经完成!"<<endl;
return OK;
}
}
return OK;
}
void main()
{ ALGraph f;
printf("教学计划编制问题的数据模型为拓扑排序AOV-网结构。\n");
printf("以下为教学计划编制问题的求解过程:\n");
printf("请输入学期总数:");
scanf("%d",&xqzs);
printf("请输入学期的学分上限:");
scanf("%d",&xfsx);
CreateGraph(&f);
Display(f);
TopologicalSort(f);
}

㈥ c++课程设计源代码

c++课程设计 学生管理系统源代码
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef struct stu
{
char name[20];
long int number;
int snum;
char sex[20];
char add[30] ;
char time[20];
char tel[20];
struct stu *next;
}stu,*student;
int init(student &s);
void insert(student &s);
void print(student &s);
int delete(student &s);
void find (student &s);
void findname(student &s);
void findnum(student &s);
void modifay(student &s);
void putfile(student &s);
void getfile(student &s);

void main()
{
student s;
init(s);
cout<<"欢迎使用学生管理系统."<<endl;
cout<<" "<<endl;
cout<<endl;
while(1)
{
int i;
mainint:
cout<<"请选择相关操作:"<<endl<<"1.建立学生资料文件."<<endl<<"2.浏览."<<endl<<"3.删除."<<endl;
cout<<"4.查询."<<endl<<"5.修改."<<endl<<"6.打开学生文件."<<endl<<"7.退出管理系统." <<endl<<"请选择:";
cin>>i;
if(i<0||i>7)
{
cout<<"输入了错误的数字,Again!"<<endl<<endl;
goto mainint;
}
switch(i)
{
case 1: insert(s);break;
case 2: print(s);
putfile(s);
break;
case 3: ldelete(s);break;
case 4: find(s);break;
case 5: modifay(s);
break;
case 6: getfile(s);break;
case 7: exit(0);
}
}

}
int init(student &s)
{
s=(student)malloc(sizeof(stu));
if (s)
{
s->next=NULL;
return 0;
}
else return -1;
}
void insert(student &s) //insert
{
cout<<endl;
student p,q;
p=(student)malloc(sizeof(stu));
cout<<"请输入学生信息:"<<endl;
cout<<"姓名:";
cin>>p->name;
cout<<endl;
cout<<"学号:";
cin>>p->number;
cout<<endl;
cout<<"性别:";
cin>>p->sex;
cout<<endl;
cout<<"家庭住址:" ;
cin>>p->add;
cout<<endl;
cout<<"出生年月:" ;
cin>>p->time;
cout<<endl;
cout<<"宿舍号:";
cin>>p->snum;
cout<<endl;
cout<<"宿舍号码:";
cin>>p->tel;
q=s;
while(!(q->next==NULL)&&(q->next->number<p->number))
q=q->next;
p->next=q->next;
q->next=p;
//if()p->next=NULL;
//free(p);

}
int ldelete(student &s) //delete
{
cout<<endl;
student p,a;
p=s ;
cout<<"请输入删除的学号:";
long int number;
cin>>number;
while(p)
{ if (p->number==number)
{
a->next=p->next;
free(p); return(0);}
else
{ a=p;
p=p->next;} }
cout<<"没有找到你要删除的选项!"<<endl<<endl;return(-1);
}
void print(student &s)
{
int a;
a=0;
student p;
p=s->next;
cout<<"姓名 "<<"学号 " <<"性别 "<<"家庭住址 "<<"出生年月 "<<"宿舍号"<<"宿舍号码"<<endl;
while(p)
{
a++;
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
p=p->next;
}
cout<<endl;
if (a==0)
cout<<"还没有学生信息!"<<endl<<endl ;
}
void find (student &s) //find
{
findl:
cout<<"请选择查找方法:"<<endl<<"1.按姓名查找."<<endl<<"2.按学号查找."<<endl;
cout<<"请选择:";
int k;
cin>>k;
if(k<0||k>3)
{
cout<<"输了入错误数字,Again!"<<endl<<endl;
goto findl;
}

switch(k)
{
case 1: findname(s);break;
case 2: findnum(s);break;
}
}

void findname(student &s) //find by name
{
student p;
p=s->next;
cout<<"请输入姓名:";
char name[20];
int j;
j=0;
cin>>name;
cout<<"你要查找的资料是:"<<endl;
cout<<"姓名 "<<"学号 " <<"性别 "<<"家庭住址 "<<"出生日期 "<<"宿舍号 "<<"宿舍号码"<<endl;
while(p)
{
if (strcmp(p->name,name)==0)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
j++;
}
p=p->next;
}
cout<<endl;
if(j==0)
cout<<"对不起,没找到你要的信息!"<<endl<<endl ;
}
void findnum(student &s) //find by number
{
student p;
p=s->next;
cout<<"请输入学号:";
long int number;
int j;
j=0;
cin>>number;
cout<<"你要查找的资料是:"<<endl;
cout<<"姓名 "<<"学号 "<<"性别 "<<"家庭住址 "<<"出生日期 "<<"宿舍号 "<<"宿舍电话"<<endl;
while(p)
{
if (p->number==number)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
j++;
}
p=p->next;
}
cout<<endl;
if(j==0)
cout<<"对不起,没找到你要的信息"<<endl<<endl ;
}
void modifay(student &s) //modifay
{
student q,p,l,m;
int j;
j=0;
q=s->next;
l=s;
m=s;
cout<<"请输入要修改的学号:" ;
long int num;
cin>>num;
cout<<"姓名 "<<"学号 "<<"性别 "<<"家庭住址 "<<"入学时间 "<<"宿舍号 "<<"电话号码"<<endl;
while(q)
{
if (q->number==num)
{
cout<<"你要修改的信息是:"<<endl;
cout<<q->name<<" "<<q->number<<" "<<q->sex<<" "<<q->add<<" "<<q->time<<" "<<q->snum<<" "<<q->tel<<" "<<endl;
j++;
p=(student)malloc(sizeof(stu));
cout<<"请输入新的学生信息:"<<endl;
cout<<"姓名:";
cin>>p->name;
cout<<endl;
cout<<"学号:";
cin>>p->number;
cout<<endl;
cout<<"年龄:";
cin>>p->age;
cout<<endl;
cout<<"性别:";
cin>>p->sex;
cout<<endl;
cout<<"家庭住址:" ;
cin>>p->add;
cout<<endl;
cout<<"入学时间:" ;
cin>>p->time;
cout<<endl;
cout<<"电话号码:";
cin>>p->tel;
l->next=q->next;
free(q);
goto tt;
}
else
{
l=q;
q=q->next;
}
}
cout<<endl;
if (j==0) cout<<"没找到你要的数据!"<<endl<<endl ;
tt:
while(!(m->next==NULL)&&(m->next->number<p->number))
m=m->next;
p->next=m->next;
m->next=p;
}
void putfile(student &s)
{
student p;
p=s->next;
FILE *fp;
if((fp=fopen("information.txt","w"))==NULL)
{
cout<<"打不开文件"<<endl<<endl;
exit(0);
}
while(p)
{
if(fwrite(p,sizeof(struct stu),1,fp)!=1 )
{
cout<<"文件写入错误"<<endl<<endl;
return;
}
p=p->next;
}
fclose(fp) ;
}
void getfile(student &s)
{
student p,q;
q=s;
FILE *fp1 ;
if((fp1=fopen("information.txt","r"))==NULL)
{
cout<<"打不开文件"<<endl;
exit(0);
}
cout<<"姓名 "<<"学号 "<<"性别 "<<"家庭住址 "<<"入学时间 "<<"宿舍号 "<<"电话号码"<<endl;
p=(student)malloc(sizeof(stu));
while(fread(p,sizeof(struct stu),1,fp1)!=0)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->age<<" "<<p->tel<<endl;
while(!(q->next==NULL)&&(q->next->number<p->number))
q=q->next;
p->next=q->next;
q->next=p;
p=(student)malloc(sizeof(stu));
}
fclose(fp1);
cout<<endl;
}

阅读全文

与课程设计源码是什么相关的资料

热点内容
php地址重写 浏览:342
网上练瑜伽用什么app最好 浏览:555
文件夹为何搜索不了 浏览:338
怎么快捷删除lol换肤文件夹 浏览:251
pdf填字 浏览:296
opencv立体匹配算法 浏览:459
什么app软件排第一 浏览:321
c语言仅可以编译么 浏览:792
mfc的按钮编程 浏览:579
linuxnandflash驱动 浏览:86
电影词典pdf 浏览:966
农夫山泉app登不上去是什么原因 浏览:432
如何赶走程序员 浏览:910
用支付宝登录阿里云服务器 浏览:877
阿里云服务器怎么更改ip 浏览:643
pvp和普通服务器有什么区别 浏览:706
pc收银台系统源码 浏览:624
程序员老公要加班 浏览:961
51单片机控制的超声波 浏览:827
2021去水印最新源码 浏览:232