㈠ 用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程序需要以下步驟:
設計資料庫:首先需要設計一個資料庫來存儲職業信息。可以創建一個名為「Careers」的表,包含職業名稱、薪資范圍、工作要求等欄位。
設計用戶界面:使用VB設計一個用戶友好的界面,包括菜單欄、工具欄和狀態欄等。在狀態欄中顯示當前選中的職業和相關信息。
實現查詢功能:提供一個查詢框,讓用戶輸入關鍵字進行搜索。根據關鍵字從資料庫中查詢相應的職業信息,並將結果顯示在列表框中。
實現添加功能:提供一個添加按鈕,讓用戶輸入職業名稱、薪資范圍和工作要求等信息,並將信息添加到資料庫中。
實現刪除功能:提供一個刪除按鈕,讓用戶選擇要刪除的職業,並將其從資料庫中刪除。
實現修改功能:提供一個修改按鈕,讓用戶選擇要修改的職業,並將其薪資范圍和工作要求等信息進行修改。
實現保存功能:提供一個保存按鈕,將用戶輸入的信息保存到資料庫中。
㈦ vc 6.0怎麼使用,怎麼編寫程序
VC 6.0的使用方法及編寫程序的步驟:
一、打開VC 6.0並創建工程
啟動VC 6.0:
新建工程:
二、創建並編寫源文件
添加源文件:
編寫代碼:
三、編譯和運行程序
編譯程序:
運行程序:
通過以上步驟,你就可以在VC 6.0中創建、編寫、編譯和運行C或C++程序了。