導航:首頁 > 編程語言 > 編寫選擇的程序

編寫選擇的程序

發布時間:2025-06-16 16:05:39

㈠ 用ASP.NET編寫程序,顯示10個單項選擇,提交後,顯示正確答案的個數及分數

(1)在設計中拉十個RadioButton控制項和一個Button控制項。雙擊Button控制項,寫入以下代碼

protected void Button1_Click(object sender, EventArgs e)
{
int n=0;
int i=0;
if(RadioButton1.Checked==true)
{
n=n+10;
i++;

}
if(RadioButton2.Checked==true)
{
n=n+10;
i++;
}
........
if(RadioButton10.Checked==true)
{
n=n+10;
i++;
}
}
你將n打出來它就是你要的分數,而i就是正確答案的個數
(2)Gridview中的RadioButton
在Gridview中放了一個radiobutton組
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" SelectedIndex="0" Width="343px" OnSelectedIndexChanged="papersubmit_Click">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label id=sque runat=server Text='<%# Eval("Ques_Squc") %>' ></asp:Label></br>
<asp:Label id=key runat=server Text='<%# Eval("Answe_Key") %>' Visible=false></asp:Label>

<asp:RadioButton id=RadioButton1 runat="server" Text='<%# Eval("Answer_A") %>' GroupName='<%# Eval("Ques_Squc") %>' ></asp:RadioButton></br>
<asp:RadioButton id=RadioButton2 runat="server" Text='<%# Eval("Answer_B") %>' GroupName='<%# Eval("Ques_Squc") %>' ></asp:RadioButton></br>
<asp:RadioButton id=RadioButton3 runat="server" Text='<%# Eval("Answer_C") %>' GroupName='<%# Eval("Ques_Squc") %>' ></asp:RadioButton></br>
<asp:RadioButton id=RadioButton4 runat="server" Text='<%# Eval("Answe_D") %>' GroupName='<%# Eval("Ques_Squc") %>' ></asp:RadioButton></br>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="Lb_Score" runat="server" Enabled="False" Text="Label" Width="144px" ForeColor="Red" Visible="False"></asp:Label>
<asp:SqlDataSource ID="paperconn" runat="server" ConnectionString="<%$ ConnectionStrings:paperconn %>"
SelectCommand="SELECT [Answer_A], [Answer_B], [Answer_C], [Answe_D], [Answe_Key], [Ques_Squc], [Ques_Title] FROM [Ques_Info] WHERE ([File_ID] = @File_ID) ORDER BY [Ques_Squc]">
<SelectParameters>
<asp:Parameter Name="File_ID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Button ID="papersubmit" runat="server" OnClick="papersubmit_Click" Text="交卷" /></div>
結果點擊"交卷"按鈕後執行 protected void papersubmit_Click(object sender, EventArgs e)
{
int score = 0;
foreach (GridViewRow dr in GridView1.Rows)
{
string str = "";
string key = "";
key = ((Label)GridView1.Rows[0].FindControl("key")).Text;
int radio_pre = GridView1.Controls.Count;
if (((RadioButton)dr.FindControl("RadioButton1")).Checked)
{
str = "A";
}
else if (((RadioButton)dr.FindControl("RadioButton2")).Checked)
{
str = "B";
}
else if (((RadioButton)dr.FindControl("RadioButton3")).Checked)
{
str = "C";
}
else if (((RadioButton)dr.FindControl("RadioButton4")).Checked)
{
str = "D";
}

if (str == key)
score = score + 1;
}
Lb_Score.Visible = true;
Lb_Score.Text = "你答對了" + score.ToString() + "個題";
}

㈡ c語言 如何用switch語句編寫一個有關商場購物金額優惠的選擇程序

#include <stdio.h>

int main(int argc, char** argv)
{
int amount = 0;
scanf("%d", &amount);//輸入顧客購買的總額
int status = amount/1000;
switch (status)
{
case 0: break;
case 1: amount = amount * 0.95; break;
case 2: amount = amount*0.90; break;
case 3: amount *= 0.85; break;
default: amount *= 0.80; break;
}
printf("%d\n", amount);//列印出打折後的總額

return 0;
}

㈢ 編寫一個程序,用選擇法對數組a[]={20,10,50,40,30,70,60,80,90,100}進行從大到小的排序

//編寫程序用冒泡方法對數組a[]={20,10,50,40,30,70,60,80,90,100}進行由大到小的排序
public class BubbleSort //冒泡排序Bubble Sort
{
public static void main(String args[]) //編輯主函數main
{
int i,j; //定義兩個變數i,j
int a[]={20,10,50,40,30,70,60,80,90,100};//定義一個數組
int l=a.length; //初始化數組長度
for(i=0;i<l-1;i++) //排序
for(j=i+1;j<l;j++) //
if(a[i]<a[j])
{
int max=a[i];
a[i]=a[j];
a[j]=max; //比較數值的大小
}
for(i=0;i<10;i++) //輸出結果
System.out.println(a[i]);
}
}

㈣ 編寫一個C語言程序,顯示如下菜單並實現相應的菜單選擇功能

/*本程序沒有採用嚴格的措施防止錯誤的輸入,
所以請在看源程序之後再輸入。
運行後會有如下提示:
「請輸入你的選擇及整數n(用逗號來間隔):」
這時可以輸入這樣的選擇:「1,2」,即求2的立方
「2,125」,即求125的立方根
「3」,退出程序*/

#include<stdio.h>
#include<math.h>

display();
lifang(n);
lifanggen(n);

main()
{
int choice,number;
display();
printf("請輸入你的選擇及整數n(用逗號來間隔):\n");
scanf("%d,%d",&choice,&number);
switch(choice)
{
case 1:
lifang(number);
break;
case 2:
lifanggen(number);
break;
case 3:
break;
}
}

display()
{
printf("************************************************\n");
printf("1.求整數n的立方\n");
printf("2.求整數n的立方根\n");
printf("3.結束程序\n");
printf("************************************************\n");
}

lifang(n)
{
double val=n;
int time=3;
printf("%lf\n\n\n",pow(val, time));/*如果將%lf-->%d就不能得出結果*/
main();/*這里是簡單的調用主函數來返回初始選擇列表,還有其他方法實現*/
}

lifanggen(n)
{
double val=n;
double time=0.333333333333333;
/*這里為近似的1/3的值,因為要求
一個數字的立方根需要用到求立方根的演算法,這里為求省事沒有給出
網路里邊可以搜到*/
printf("%lf\n\n\n",pow(val,time));
main();
}

㈤ 從鍵盤輸入10個整數,編寫程序用選擇排序法對這十個數降序排列,要求主函數功能

include<stdio.h>

int main()

{int i,j,k,t,a[10];

for(i=0;i<10;i++) //輸入10個整數

scanf("%d",&a[i]);

for(i=0;i<9;i++) //排序10個數,需要9輪

{k=i; //當前最小值的編號

for(j=i+1;j<10;j++) //掃描後續所有元素

if(a[j]<a[k])k=j; //如後面的元素更小,就更新最小編號

t=a[i]; a[i]=a[k]; a[k]=t; //把最小的元素交換到第 i 位

}

for(i=0;i<10;i++) //輸出排好序的元素值

printf("%d ",a[i]);

return 0;

}

㈥ 職業選擇的整合的vb程序怎麼寫

編寫一個整合職業選擇的VB程序需要以下步驟:

㈦ vc 6.0怎麼使用,怎麼編寫程序

VC 6.0的使用方法及編寫程序的步驟

一、打開VC 6.0並創建工程

  1. 啟動VC 6.0

    • 首先,確保你已經正確安裝了Microsoft Visual C++ 6.0(VC 6.0)。
    • 點擊桌面上的VC 6.0圖標或開始菜單中的相應選項來啟動它。
  2. 新建工程

    • 在VC 6.0的主界面中,點擊菜單欄上的「文件」選項。
    • 選擇「新建」,彈出新建對話框。
    • 在對話框中選擇「工程」選項,並鍵入你想要的工程名(自定義命名)。
    • 選擇一個空的工程模板(通常會有一個紅框標記的選項,表示這是常用的選擇)。
    • 點擊「完成」,然後點擊「確定」來創建工程。

二、創建並編寫源文件

  1. 添加源文件

    • 在創建好工程後,再次點擊「文件」選項,選擇「新建」。
    • 這次選擇「文件」選項,並在彈出的對話框中選擇「C++ Source File」(對於C語言程序,也可以選擇「C Source File」)。
    • 鍵入你想要的文件名,並點擊確定。
  2. 編寫代碼

    • 此時,VC 6.0會打開一個新的編輯窗口,你可以在這個窗口中編寫你的C或C++代碼。
    • 使用VC 6.0提供的代碼編輯功能,如語法高亮、自動縮進等,來方便地編寫和修改代碼。

三、編譯和運行程序

  1. 編譯程序

    • 編寫完代碼後,點擊菜單欄上的「構建」選項,然後選擇「構建當前工程」或按快捷鍵F7來編譯你的程序。
    • 如果代碼中有錯誤,VC 6.0會在輸出窗口中顯示錯誤信息,你需要根據這些信息來修改代碼。
  2. 運行程序

    • 編譯成功後,你可以點擊「構建」選項下的「執行當前工程」或按快捷鍵Ctrl+F5來運行你的程序。
    • 程序運行後,你可以在控制台窗口中看到輸出結果。

通過以上步驟,你就可以在VC 6.0中創建、編寫、編譯和運行C或C++程序了。

閱讀全文

與編寫選擇的程序相關的資料

熱點內容
Iphone換電池升級系統 瀏覽:875
筆記本開機連不上網路 瀏覽:336
主從資料庫怎麼同步 瀏覽:970
玻璃杯裝飾教程 瀏覽:659
ps文件列印背景灰色 瀏覽:861
凱利指數在哪個app看 瀏覽:746
聯想家悅e1305升級 瀏覽:656
stm32l0程序例子下載 瀏覽:609
特斯拉app要用什麼更新 瀏覽:969
能列印機錯誤代碼306 瀏覽:769
伺服器配置文件管理 瀏覽:964
word頁眉圖片 瀏覽:733
奇跡刷怪文件 瀏覽:691
3ds上哪找sd卡文件夾 瀏覽:564
數控編程怎麼用ijk 瀏覽:991
小米note總是自動關閉程序 瀏覽:235
什麼買菜app邀請有獎勵 瀏覽:58
數據挖掘什麼是組件 瀏覽:81
團建文件夾圖片 瀏覽:473
怎麼修改手機文件後綴名 瀏覽:877

友情鏈接