㈠ 用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++程序了。