當前位置:首頁 » 軟體設計 » 程序設計實訓

程序設計實訓

發布時間: 2021-01-19 09:52:38

A. 程序設計實訓。。

時間過的真快來,轉眼間我期望已源久的實訓周已經結束。經過一周的實訓練習讓我學到了許多知識,回頭想想實訓這幾天我確實是有很大收獲的。
這次實訓讓我明白了我們實訓的主要目的是讓我們通過不斷的上機實習以及使用它來解決實際的問題,才能更好的掌握所學技能。實踐出真理,在這一周的實訓確實是有瞞累但是累得有價值。學海無涯,好多好多的東西在向我們招手,等待我們去努力的開發學習。再接再厲吧,希望自己可以真正的懂了,加油!在以後的工作、生活和學習中,發展自己的優勢,彌補自己的不足和缺陷。

不足之處希望老師多多指點!!

B. 《Java程序設計》實訓

Counter類如下:
class Counter {
private int countValue;

Counter(){countValue = 0;}
Counter(int count){countValue = count;}

public void increment(){
++countValue;
}

public boolean decrement(){
if(countValue == 0) return false;
else --countValue;
return true;
}

public void reset(){
countValue = 0;
}

public void set(int count){
countValue = count;
}

public int getCount(){return countValue;}
}

測試類如下:
public class Test{
public static void main(String[] args) {
Counter test = new Counter();
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("請輸入投影儀使用情況(Buy(1),Receive(2),Discard(3),Lend(4),Reset(5),Set(6))");
int command;
while(true) {
command = sc.nextInt();
switch(command){
case 1:
case 2:
test.increment();
break;
case 3:
case 4:
if(!test.decrement()) System.out.println("實驗室已經沒有投影儀了");
break;
case 5:
test.reset();
break;
case 6:
test.set(sc.nextInt());
break;
default:
System.out.println("無效的命令");
}
System.out.println("現在實驗室有投影儀" + test.getCount() + "台");
}
}
}

分別寫在Counter.java和Test.java中,放在同一目錄下即可使用,測試結果為:
請輸入投影儀使用情況(Buy(1),Receive(2),Discard(3),Lend(4),Reset(5),Set(6))
6
10
現在實驗室有投影儀10台
1
現在實驗室有投影儀11台
2
現在實驗室有投影儀12台
3
現在實驗室有投影儀11台
4
現在實驗室有投影儀10台
5
現在實驗室有投影儀0台
3
實驗室已經沒有投影儀了
現在實驗室有投影儀0台

C. C語言程序設計的實訓題,急!

第一題:
#include "stdio.h"

main(){
int n = 4;
float sum =0;
int i;

for(i=1;i<=n;i++)
sum = sum +(float)i/((2*i-1)*(2*i+1));

printf("sum = %.2f",sum);
getch();
}

第二題:

#include "stdio.h"

main(){
int line = 5;
int i,j;

for(i=1;i<=line;i++){
for(j=0;j<6;j++)
printf("%d ",i);
printf("\n");
}
getch();
}

希望能幫到你。。專。。仍有問屬題可以HI我。。。。

D. C語言程序設計 實訓,急

第2題;
#include<stdio.h>
void main()
{
char *p[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int i;
printf("please input a number:\n");
scanf("%d",&i);
switch(i)
{case 1:printf("Monday\n");break;
case 2:printf("Tuesday\n");break;
case 3:printf("Wednesday\n");break;
case 4:printf("Thursday\n");break;
case 5:printf("Friday\n");break;
case 6:printf("Saturday\n");break;
case 7:printf("Sunday\n");break;
default:break;
}
}
運行結果是:
please input a number:
3
Wednesday
第3題:
#include<stdio.h>
struct student
{ char no[5];
char name[10];
int score[4];
double average;
};
void readrec(struct student s[5])
{
int i;
printf("please input 5 students'information\n");
for(i=0;i<5;i++)
{s[i].average=0.0;
scanf("%s%s%d%d%d%d",s[i].no,s[i].name,&s[i].score[0],&s[i].score[1],&s[i].score[2],&s[i].score[3]);
s[i].average=(s[i].score[0]+s[i].score[1]+s[i].score[2]+s[i].score[3])/4.0;
}
}
void writerec(struct student s[5])
{
int j;
for(j=0;j<5;j++)
{printf("%s %s %d %d %d %d %f",s[j].no,s[j].name,s[j].score[0],s[j].score[1],s[j].score[2],s[j].score[3],s[j].average);
printf("\n");}
}
void main()
{struct student s[5];
readrec(s);
printf("these 5 students'information are:\n");
writerec(s);
}
運行結果是:
please input 5 students'information
1061 lili 76 75 74 78
1062 wangsui 80 87 84 86
1063 huangsi 76 74 80 91
1064 chengong 82 87 89 90
1094 huwei 90 100 64 80
these 5 students'information are:
1061 lili 76 75 74 78 75.750000
1062 wangsui 80 87 84 86 84.250000
1063 huangsi 76 74 80 91 80.250000
1064 chengong 82 87 89 90 87.000000
1094 huwei 90 100 64 80 83.500000
第4題不會
第5題
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#include<stdio.h>
void main()
{
FILE *fp;
char ch,s[1024];
int i;
fp=fopen("/home/ccx/mydocument/filename","wb+");
printf("請輸入10個字元串,以『#'結束!\n");
ch=getchar();
while(ch!='#')
{fputc(ch,fp);
ch=getchar();
}
fclose(fp);
printf("你所輸入的字元串是\n");
fp=fopen("/home/ccx/mydocument/filename","r");
while(TRUE)
{memset(s,0,sizeof(s));
if(fgets(s,1000,fp)==FALSE) break;
printf("%s",s);
printf("\n");
}
fclose(fp);
}
運行結果是:
請輸入10個字元串,以『#'結束!
hahsg xhajkf ahaua dhaak xhaj23 shka8 ./alsj shasif shjkx akaj#
你所輸入的字元串是
hahsg xhajkf ahaua dhaak xhaj23 shka8 ./alsj shasif shjkx akaj

E. 誰能幫我寫程序設計實訓報告呀

只是個例子,不可照抄。
實驗內容與要求:
[實驗內容]
1、 通過本試驗初步培養計算機邏輯解題能力。熟練掌握賦值語句和if語句的應用;掌握switch多路分支語句和if嵌套語句的使用
2、 將前期所學習到的基本數據類型、運算符和表達式等程序設計基礎知識運用於具體的程序設計。
3、 進一步熟練掌握輸入輸出函數scanf, printf和getchar的使用,熟悉math.h中常用數學函數的使用方法
4、 掌握循環語句的應用方法。
5、 了解隨機數生成函數。
[實驗要求]
在規定期限獨立完成實驗內容
1、 提交實驗報告(電子版)
2、 提交相應源程序文件(文件名 EX6_x姓名.c, 如EX6_1彭健.c)
3、 要求從簡單到復雜,後面的要求均在前面的基礎上進行修改,前六題,每題均需要保留各自的程序,六題以後,每題均在前一題基礎上修改,保留最後一個程序即可(如做到第九題,則保留EX6_9姓名.c,做到第11題,則保留ex6_11姓名.c)
二、實驗原理和設計方案:
1、函數頭的選則,while循環語句,switch(case)語句,條件表達式,if else條件語句,自增運算符,設置復雜變數,輸出隨機操作數。
2、 變數要有分數變數和等級變數,要有選擇演算法題數的變數和計算正確與否的變數,要有隨機輸出的兩個操作數變數和自己按運算符號輸入結果的變數,最後還有判斷是否要進行的變數字元。中間結果有選擇運算符的switch()和分數等級的switch()和錯題對題的自增和選擇運算符計算的自增。
3、 問題的分析方法:先考慮設置整形變數和字元變數,考慮到要不斷循環計算,選擇用while語句來循環。在循環體中,將前面的輸出提示運算符,和自行選擇運算符、答案及輸出隨機操作數完成。再用switch語句對選擇的運算符進行判斷,並用變數進行自增運算,計算出錯題於對題個數和選擇了那種運算符號。在循環體最後用if else語句來判斷是否繼續執行還是跳出循環。最後根據自增計算的結果和公式進行分數計算,並用switch語句來是想等級的制定。
三、源代碼
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
..........
}
四、試驗結果和啟發
因為輸入y要繼續循環,所以選擇用while語句。在while語句中要結合前面的按提示計算,並嵌套switch語句並用條件表達式,來計算結果正確與否,計算的題型是什麼。最後再用switch語句來完成分數等級的判斷。
五、實驗體會:
描述自己在編程或程序編譯運行中遇到的難點和問題及解決的辦法。

F. c語言程序設計實訓

1,

#include<stdio.h>
voidmain()
{
inta=10,b=25,t;
t=a;
a=b;
b=t;
printf("a=%d,b=%d ",a,b);
}

2,

#include<stdio.h>
voidmain()
{
intn,a,b,c,d;
printf("請輸入一個四位數: ");
scanf("%d",&n);
while(n<1000||n>9999)
{
printf("ERROR! ");
printf("請輸入一個四位數: ");
scanf("%d",&n);
}
a=n%10;
n=n/10;
b=n%10;
n=n/10;
c=n%10;
d=n/10;
/*以上a,b,c,d代表原來四位數的個、十內、百、千容位*/
n=1000*d+100*b+10*c+a;
printf("調換後的數:%d ",n);
}


PS ::不懂還可繼續問。。。

G. C 語言程序設計~實訓~急急急!!!

天啊,你什麼學校畢業的,這么簡單,我才大一,c只學了一半我都基本會做。這樣吧,我選擇性的給你做幾個,要給我分哈

2,完數

#include <stdio.h>
void main()
{
int i,j,sum=0;
for (i=2;i<=1000;i++)
{
for (j=1;j<=i/2;j++)
if (i%j==0) sum=sum+j;
if (sum==i) printf("%d\n",sum);
sum=0;
}

}

實在沒心情寫了,用switch的很不想寫。就是c的教材上都有的例題。

一下是統計字元那個題

#include <stdio.h>
void main()
{
char a[1000],b[1000];
int i,j,c[1000],num=0;
scanf ("%s",&a);
for (i=0;i<1000;i++)
{
c[i]=0;
}
for (i=0;a[i]!='\0';i++)
{
for (j=0;j<=num;j++)
{
if (a[i]==b[j])
{
c[j]++;
break;
}
if (j==num&&a[i]!=b[num])
{
b[num]=a[i];
c[num]++;
num++;
break;
}
}
}
for (i=0;i<=num-1;i++)
{
printf("%c",b[i]);
printf("%d個\t",c[i]);
}
printf("\n");
}

一下為求素數

#include <stdio.h>
void main()
{
int a,i;
scanf ("%d",&a);
for (i=2;i<=a/2;i++)
{
if (a%i==0)
{
printf("不是素數\n");
break;
}
}

if (i==a/2) printf("是素數\n");

}

熱點內容
美發店認證 發布:2021-03-16 21:43:38 瀏覽:443
物業糾紛原因 發布:2021-03-16 21:42:46 瀏覽:474
全國著名不孕不育醫院 發布:2021-03-16 21:42:24 瀏覽:679
知名明星確診 發布:2021-03-16 21:42:04 瀏覽:14
ipad大專有用嗎 發布:2021-03-16 21:40:58 瀏覽:670
公務員協議班值得嗎 發布:2021-03-16 21:40:00 瀏覽:21
知名書店品牌 發布:2021-03-16 21:39:09 瀏覽:949
q雷授權碼在哪裡買 發布:2021-03-16 21:38:44 瀏覽:852
圖書天貓轉讓 發布:2021-03-16 21:38:26 瀏覽:707
寶寶水杯品牌 發布:2021-03-16 21:35:56 瀏覽:837