導航:首頁 > 源碼編譯 > 課程設計源碼是什麼

課程設計源碼是什麼

發布時間: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;
}

閱讀全文

與課程設計源碼是什麼相關的資料

熱點內容
redhatphp 瀏覽:454
android智能家居藍牙 瀏覽:646
pt螺紋編程 瀏覽:451
手機電音app哪個好 瀏覽:749
checksum命令 瀏覽:637
java創建xml文件 瀏覽:170
算命源碼國際版 瀏覽:283
三菱模塊化編程 瀏覽:718
控制項讀取文件源碼 瀏覽:445
文件夾側面目錄標簽怎麼製作 瀏覽:232
做程序員學什麼 瀏覽:320
pdfeditor教程 瀏覽:880
fortran把文件放入文件夾 瀏覽:709
程序員1年經驗不敢投簡歷 瀏覽:481
如何看電腦的源碼 瀏覽:897
找工作app軟體哪個好 瀏覽:96
信息管理網站源碼 瀏覽:439
小說app哪個好免費 瀏覽:224
域名在線加密 瀏覽:146
軟體編程西安交大 瀏覽:453