當前位置:首頁 » 編程語言 » c語言程序設計項目教程第二章筆記
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言程序設計項目教程第二章筆記

發布時間: 2022-06-14 21:38:22

c語言程序設計的筆記

自己學唄,要什麼筆記啊,自己不能記啊,是不是要考試了,想看一下啊,我感覺編程靠突擊是很不現實的,你自己找老師同學復印點不就行了

Ⅱ 《C語言程序設計》項目設計

這種東西很多了,隨便搜索一大堆:這是個學生成績的!
#include <iostream.h>
#include <iomanip.h>
#include <fstream>
#include <vector>
#include <malloc.h>
#include <stdlib.h>
#include <string>
#include <process.h>
#include <stdio.h>
//#define NULL 0
int const Q=20;
#define LEN sizeof(struct student)
using namespace std;
int n=0; //定義一個全局變數統計學生人數
//——--------->定義一個學生考試信息的結構體
struct student
{
char name[Q]; //用來存放姓名的
char sex[Q]; //用來存放性別的
long int id; //用來存放准考證號的
int score[4]; //用來存放分數的
int total; //用來存放總分數的
struct student *next;
};
//student向量容器
vector <student> stu;
//-------------->學生類
class Information
{
public:
Information() ; //構造函數.
~Information() ; //析構函數.
student *creat();//建立鏈表函數。
void output(student *head);
int count(student *head);//定義函數count()統計考生總數
student *insert(student*head);//指針函數*insert()用來添加考生信息.
student *cancel(student *head,long int num);//指針函數*cancel()用來刪除考生信息.
student *find(student *head,long int num); //指針函數*find()用來查找考生信息.
void inorder(student *head);//定義inorder()函數將考生的總分從大到小排列並輸出
void average( student *head);//求學生成績的平均分的函數
void save(student *head);//保存函數
student *Read();//讀取函數
private:
student *p1,*p2,*p3,*head,st;
};
Information::Information()
{
cout<<" ******************************************************************************\n";
cout<<" ------------------------<<歡迎您使用學生成績管理系統>>------------------------\n";
cout<<" ******************************************************************************\n\n";
}
Information::~Information()
{
cout<<" ******************************************************************************\n";
cout<<" ------------------------<<謝謝您使用學生成績管理系統>>------------------------\n";
cout<<" ******************************************************************************\n";
}
student *Information::creat(void)
{//定義一個指向struct student的結構體指針函數*creat()用來增加考生信息.
char ch[Q];n=0; //用來存放姓名的
p1=p2=(student *)malloc(LEN);//調用malloc()函數用來開辟一個新的存儲單元
cout<<" -------------<<請建立學生考試信息表,在姓名處鍵以 ! 結束輸入。>>--------------"<<endl;
cout<<" 姓名:";
cin>>ch;
head=NULL; //給指針head賦初值
while (strcmp(ch,"!")!=0)
{//調用字元比較函數strcmp()用來判斷是否繼續輸入
char str[10];
int flag=0;
p1=(student *)malloc(LEN);//調用malloc()函數用來開辟一個新的存儲單元
strcpy(p1->name,ch); //將循環結構前面輸入的姓名復制到結構體名為p1的數組name中
cout<<" 性別:";
cin>>p1->sex;

cout<<" 准考證號(8位):";
do{
cin>>str;
if(atol(str)>99999999 || atol(str)<1)
cout<<"對不起,請正確輸入!!!\n";
else
{
p1->id=atol(str); flag=1;
}
}while(flag==0);

flag=0;

cout<<" 計算機組成原理成績:";
do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{
p1->score[0]=atoi(str); flag=1;
}
}while(flag==0);

flag=0;

cout<<" 概率統計成績:";

do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[1]=atoi(str); flag=1;}
}while(flag==0);

flag=0;

cout<<" 英語成績:";

do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[2]=atoi(str); flag=1;}
}while(flag==0);
flag=0;

cout<<" C++成績:";

do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[3]=atoi(str); flag=1;}
}while(flag==0);

flag=0;

p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];//計算總分
if(n==0)head=p1;//如果是輸入第一組學生考試信息就將指針p1賦給指針head
else p2->next=p1;//否則將p1賦給p2所指結構體的next指針
p2=p1;//將指針p1賦給指針p2
n++; //將n的值加1
cout<<" 姓名:";
cin>>ch;//將輸入的姓名存放到字元數組ch中
}
p2->next=NULL;//將p2所指結構體的next指針重新賦空值
return (head);//將輸入的第一組學生考試信息返回
}
//--------------->定義output()函數將考生的信息從頭指針所指內容開始輸出
void Information::output(student *head)
{

if(head==NULL) cout<<" 這是一個空表,請先輸入考生成績.\n";
else{
cout<<"-------------------------------------------------------------------------------\n";
cout<<" *學生考試成績信息表*\n";
cout<<"-------------------------------------------------------------------------------\n";
cout<<"准考證號 姓 名 性別 計算機組成原理 概率統計 英語 C++ 平均分 總分\n";
cout<<"-------------------------------------------------------------------------------\n";
p1=head;//將頭指針賦給p
do
{
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(8)<<p1->sex
<<setw(13)<<p1->score[0]
<<setw(16)<<p1->score[1]
<<setw(10)<<p1->score[2]
<<setw(9)<<p1->score[3]
<<setw(6)<<p1->total/4.0
<<setw(11)<<p1->total<<endl;
cout<<"-------------------------------------------------------------------------------\n";
p1=p1->next;//將下一組考生信息的next指針賦給p
}while(p1!=NULL);//若指針p非空則繼續,目的是把所有的考生信息都傳給指針p然後輸出.
}
}
//------------>統計學生人數的函數
int Information::count(struct student *head)//定義函數count()統計考生總數
{
if(head==NULL)
return(0);//若指針head為空返回值為0
else return(1+count(head->next));//函數的遞歸調用
}
//----------->插入學生的成績的函數
student *Information::insert( student *head)
//插入新結點定義一個指向struct student的結構體指針函數*insert()用來添加考生信息.
{
char str[10];
int flag=0;
cout<<"\t----------------<<請輸入新增學生成績信息>>----------------\n"<<endl;
p1=(student *)malloc(LEN); //使p1指向插入的新結點
cout<<" 姓名:";
cin>>p1->name; //將輸入的姓名存放到結構體名為p1的數組name中
cout<<" 性別:";
cin>>p1->sex;
cout<<" 准考證號(8位):";
do{
cin>>str;
if(atol(str)>99999999 || atol(str)<1)
cout<<"對不起,請請正確輸入!!!\n";
else
{p1->id=atol(str); flag=1; }
}while(flag==0);

flag=0;

cout<<" 計算機組成原理成績:";
do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[0]=atoi(str); flag=1;}
}while(flag==0);

flag=0;

cout<<" 概率統計成績:";

do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[1]=atoi(str); flag=1;}
}while(flag==0);

flag=0;

cout<<" 英語成績:";

do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[2]=atoi(str); flag=1;}
}while(flag==0);
flag=0;

cout<<" C++成績:";

do{
cin>>str;
if(atoi(str)>100 || atoi(str)<1)
cout<<"對不起,請輸入1-100之間的數字!!\n";
else
{ p1->score[3]=atoi(str); flag=1;}
}while(flag==0);

flag=0;

p1->total=p1->score[0]+p1->score[1]+p1->score[2]+p1->score[3];//計算總分
p2=head;//將頭指針賦給p2
if(head==NULL) //若沒調用次函數以前的頭指針head為空
{
head=p1;p1->next=NULL;
}//則將p1賦給頭指針head並將p1所指結構體成員指針next賦空值
else
{
while((p1->id>p2->id)&&(p2->next!=NULL))
{
p3=p2;//p3指向原p2指向的結點
p2=p2->next;
}//p2後移一個結點
if(p1->id<=p2->id)
{
if(head==p2)
{
p1->next=head;
head=p1;
} //插入到第一個結點之前
else
{
p3->next=p1;
p1->next=p2;
} //插入到p3所指結點之後
}
else
{
p2->next=p1;
p1->next=NULL;
} //插入到尾結點之後
}
n++;//將學生人數加1
cout<<"\t你輸入的學生信息已經成功插入"<<endl;
return (head);
}
//------------>刪除函數
student *Information::cancel(student *head,long int num)//定義一個指向struct student的結構體指針函數*delete()用來刪除考生信息.
{

if(head==NULL)//若調用次函數以前的頭指針head為空
{
return(head);
}
else
{
p1=head;//否則將頭指針賦給p1
while(num!=p1->id&&p1->next!=NULL)//尋找要刪除的結點當p1所指的學生准考證號不是輸入的學生准考證號並且p1所指的next指針不為空
{
p2=p1;
p1=p1->next;
}//p2指向原p1指向的結點p1後移一個結點
if(num==p1->id)//如果輸入的學生准考證號是p1所指的學生准考證號//結點找到後刪除
{
if(p1==head) head=p1->next;//如果head指針和p1指針相等則將下一個結點賦給指針head
else
p2->next=p1->next;//否則將p1所指結點賦給p2所指結點將要刪除的學生信息跳過去
cout<<" 刪除准考證號為"<<num<<"的學生\n";
n--;//將學生人數減1
}
return(head);//將頭指針返回
}
}
//------------>查找函數
student *Information::find(student *head,long int num)
//定義一個指向struct student的結構體指針函數*find()用來查找考生信息.
{

if(head==NULL)//若調用次函數以前的頭指針head為空
{
cout<<" 這是一個空表,請先輸入考生成績.\n";
return(head);
}
else
{
p1=head;//否則將頭指針賦給p1
while(num!=p1->id&&p1->next!=NULL)
//尋找結點當p1所指的學生准考證號不是輸入的學生准考證號並且p1所指的next指針不為空
{
p1=p1->next;
}//p2指向原p1指向的結點p1後移一個結點
if(num==p1->id)//如果要查找的學生准考證號是p1所指的學生准考證號
{
cout<<"------------------------------------------------------------------------------\n";
cout<<"准考證號 姓名 性別 計算機組成原理 概率統計 英語 C++ 平均分 總分 \n";
cout<<"------------------------------------------------------------------------------\n";
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(8)<<p1->sex
<<setw(13)<<p1->score[0]
<<setw(16)<<p1->score[1]
<<setw(10)<<p1->score[2]
<<setw(9)<<p1->score[3]
<<setw(6)<<p1->total/4.0
<<setw(11)<<p1->total<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
else
cout<<" 沒找到准考證號為"<<num<<"的學生.\n"; //結點沒找到
return(head);
}
}
//------------定義inorder()函數將考生的總分從大到小排列並輸出
void Information::inorder(student *head)
{
int i,k,m=0,j;
student *p[Q];//定義一個指向struct student的結構體指針數組p
if(head!=NULL)//如果頭指針是空則繼續
{ m=count(head);
cout<<"------------------------------------------------------------------------------\n";
cout<<"學生考試成績統計表\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"准考證號 姓 名 性別 計算機組成原理 概率統計 英語 C++ 平均分 總分 名次\n";
cout<<"------------------------------------------------------------------------------\n";
p1=head;
for(k=0;k<m;k++)
{
p[k]=p1;
p1=p1->next;
}
for(k=0;k<m-1;k++) //選擇排序法
for(j=k+1;j<m;j++)
if(p[k]->total<p[j]->total)
{
p2=p[k];
p[k]=p[j];
p[j]=p2;
} //從大到小排列的指針
for(i=0;i<m;i++)
{
cout<<setw(8)<<p1->id
<<setw(9)<<p1->name
<<setw(8)<<p1->sex
<<setw(13)<<p1->score[0]
<<setw(16)<<p1->score[1]
<<setw(10)<<p1->score[2]
<<setw(9)<<p1->score[3]
<<setw(6)<<p1->total/4.0
<<setw(11)<<p1->total<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
}
//------------>求各科平均分成績的函數

void Information::average(student *head)
{

int k,m;
float arg1=0,arg2=0,arg3=0,arg4=0;
if(head==NULL)//如果頭指針是空則繼續
{
cout<<" 這是一個空表,請先輸入考生成績.\n";
}
else
{
m=count(head);
p1=head;
for(k=0;k<m;k++)
{
arg1+=p1->score[0];
arg2+=p1->score[1];
arg3+=p1->score[2];
arg4+=p1->score[3];
p1=p1->next;
}
arg1/=m;arg2/=m;arg3/=m;arg4/=m;
cout<<"全班單科成績平均分\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<" 計算機組成原理平均分:"<<setw(7)<<arg1
<<" 概率統計平均分:"<<setw(7)<<arg2
<<" 英語平均分:"<<setw(7)<<arg3
<<" C++平均分:"<<setw(7)<<arg4<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
//------------------->保存函數.
void Information::save(student *head)
{
ofstream out("data.txt",ios::out);
out<<count(head)<<endl;
while(head!=NULL)
{ out<<head->name<<"\t"
<<head->id<<"\t"<<"\t"
<<head->sex<<"\t"
<<head->score[0]<<"\t"
<<head->score[1]<<"\t"
<<head->score[2]<<"\t"
<<head->score[3]<<"\t"
<<head->total<<endl;
head=head->next;
}

}
//———————————>讀取函數的實現
student *Information::Read()
{ int i=0;
p1=p2=( student *)malloc(LEN);
head=NULL;
ifstream in("data.txt",ios::out);
in>>i;
if(i==0){cout<<" data.txt 文件中的數據為空,請先輸入數據。"<<endl; return 0;}
else {
cout<<" …………………………………………………………………………………………"<<endl;
for(;i>0;i--)
{ p1=(student *)malloc(LEN);
cin>>st.name>>st.id>>st.sex
>>st.score[0]>>st.score[1]>>st.score[2]>>st.score[3]
>>st.total;
strcpy(p1->name,st.name);
p1->id=st.id;
strcpy(p1->sex,st.sex);
p1->score[0]=st.score[0];
p1->score[1]=st.score[1];
p1->score[2]=st.score[2];
p1->score[3]=st.score[3];
p1->total=st.total;
if(n==0)head=p1;//如果是輸入第一組學生考試信息就將指針p1賦給指針head
else p2->next=p1;//否則將p1賦給p2所指結構體的next指針
p2=p1;//將指針p1賦給指針p2
n++; //將n的值加1
//顯示讀入數據
cout<<" "<<p1->name<<"\t"
<<p1->id<<"\t"<<"\t"
<<p1->sex<<"\t"
<<p1->score[0]<<"\t"
<<p1->score[1]<<"\t"
<<p1->score[2]<<"\t"
<<p1->score[3]<<"\t"
<<p1->total<<endl;
cout<<" …………………………………………………………………………………………"<<endl;
//
}
cout<<" 數據已經成功讀取完畢。"<<endl;
p2->next=NULL;
return (head);
}

}
//------------------------------>主函數.
int main(void)
{
Information person;
student *head=NULL;
char str[10];
int flag=0;
int choice;
long int i;
head=person.Read();
do{

cout<<"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓";
cout<<"┃ 學生成績管理系統主菜單界面 ┃";
cout<<"┃ 讀取數據請輸入數字零 ┃";
cout<<"┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫";
cout<<"┃ ①.輸入學生成績 ┃";
cout<<"┃ ②.顯示學生成績 ┃";
cout<<"┃ ③.排序統計成績 ┃";
cout<<"┃ ④.查找學生成績 ┃";
cout<<"┃ ⑤.增加學生成績 ┃";
cout<<"┃ ⑥.刪除學生成績 ┃";
cout<<"┃ ⑦.保存退出系統 ┃";
cout<<"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛";
cout<<"請輸入您的選擇(1--7):( )\b\b";

cin>>str;
if(atoi(str)>7 || atoi(str)<1)
cout<<"對不起,請輸入1-7這幾個數字!!\n";
else
{
choice=atoi(str);
switch(choice)
{
case 1:
head=person.creat();
break;
case 2:
person.output(head);
break;
case 3:
person.inorder(head);
person.average(head);
cout<<" 參加考試的學生人數為:"<<person.count(head)<<"人\n";
break;
case 4:
cout<<" 請輸入要查找的准考證號(8位):";
do{
cin>>str;
if(atol(str)>99999999 || atol(str)<1)
cout<<"對不起,請輸入正確輸入!!!\n";
else
{i=atol(str); flag=1; }
}while(flag==0);

flag=0;
person.find(head,i);
break;
case 5:
head=person.insert(head);
person.output(head);
break;
case 6:
cout<<" 請輸入要刪除的准考證號(8位):";
do{
cin>>str;
if(atol(str)>99999999 || atol(str)<1)
cout<<"對不起,請輸入正確輸入!!!h\n";
else
{i=atol(str); flag=1; }
}while(flag==0);

flag=0;
head=person.cancel(head,i);
person.output(head);
break;
case 7:
person.save(head);
cout<<"文件已保存!可以安全退出!!!"<<endl;
break;
default :cout<<" 對不起,您的輸入有誤,請重新輸入。\n";
break;
}
}
}while(choice!=7);

return 0;
}

Ⅲ 譚浩強C語言程序設計 第二章 演算法里的 例:2.2該怎麼用C語言解啊

int n[50]={n1,...,ni,...,n50}; // 填上學號
int g[50]={g1,...,gi,...,g50}; // 填上成績
for(i=1,i<=50;i++)
{
if(g[i-1]>=80)
printf("學號%d,成績%d\n",n[i-1],g[i-1]);
}

Ⅳ C語言程序設計這門課程第二章流程式控制制(初級)的知識點有哪些

C語言程序設計這門課第二章流程式控制制(初級)的知識點包含【初級】第10講-IF條件語句,【初級】第11講-Switch條件語句,【初級】第12講-while循環語句,【初級】第13講-For循環語句,。

Ⅳ 二級C語言程序設計教程的目錄

前言
第一章C語言概述
第二章數據類型及運算
第三章基本語句
第四章流程式控制制
第五章數組
……

Ⅵ 譚浩強《c語言程序設計》第2章演算法流程圖重要嗎

流程圖是比較重要的,在寫一個程序之前,要設計出一個流程圖,有利於指導你編寫程序,使你在編程過程知道先做什麼,後做什麼。而程序完成後,讀程序的人一看流程圖,就能清晰的把握你程序的結構,有利於讀程序著理解你的程序,在做大程序時更能體現這一點,所以,學好畫流程圖是很重要的,建議你把它學好。

Ⅶ 我想要c語言程序設計第四版的筆記

筆記是記錄在筆記本或者課本上的,要掃描才能分享出來的,有誰會去掃描啊

Ⅷ 各位有沒有C語言的學習筆記或整理好的一些資料

《c語言編程百例》,按照例子來學習比較容易上手,比直接看那些原理性的書籍強 //
是寫程序的機試還是理論的筆試?
機試推薦《程序設計引導及在線實踐》,大綱級書籍,具體鏈接:http://ai.pku.e.cn/book/
理論的筆試肯定還是以譚浩強的為主,不過確實有些亂,你不妨買本它配套的習題之類的看看,譚浩強此書配套習題相當多,基本上都大同小異,根據手頭已有的資料為主來選吧,具體不推薦了。

Ⅸ C語言編程

這個是華軍上的C/C++程序設計學習與實驗系統
介紹如下:
原名《Turbo C/C++ for Windows 集成實驗與學習環境》,現在已全面支持最新操作系統VISTA,它是從事一線教學的大學教師根據C/C++ 初學者的特點,量身定製的一個簡單易用的 C/C++程序設計學習與實驗軟體(支持TC2/TC3、GCC、VC6四種編譯器,沒有使用日期限制)。與軟體配套的《 C/C++程序設計教程(配有同步實驗、流程式控制制語句動畫演示、提供教程中所有程序實例、實驗、作業中的源代碼(全部用VC6編譯器調試通過))》融入了作者多年的教學和學習經驗、編程建議、編程感悟,新增讀書筆記功能有利用戶 記錄教程中的重點、難點、學習心得體會,針對用戶學習教程中遇到的問題開通了疑難問題解答論壇等,同時,為了便於C語言學習,加入C語言學習指導、入門程序實例、典型源程序、典型的函數演算法,課程設計指導、課程設計源程序、 Visual C++6.0中英文編譯錯誤信息同步顯示功能(並配有60多種同步的語法錯誤程序實例、修改方法等)、 Turbo C2.0 中英文編譯錯誤信息同步顯示功能、Turbo C++3.0常見編譯錯誤信息、C語言專業詞彙的中英文對照、二級 C 語言的真題筆試試卷及答案與分析和上機模擬試題和詳盡的答案與分析等大量的學習資源。另外 「編程日記」 功能可以讓你記錄你的 C 語言學習歷程, 「資料管理」 功能讓你大量的下載資料不再難找

安裝注意事項:為了保證軟體的正常運行,請不要安裝在中文文件夾中,採用默認安裝路徑即可。

2009.3版本更新

不知道你是打算用來做什麼用的?是學慣用還是工作用的?
另外,虛機團上產品團購,超級便宜