- //主要代码放在form2:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- namespace getLifespan
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- static int questionIndex = 0;//设置问题的索引
- static int lifespan = 72;//预期寿命的平均值
- int[][] answerArr;
- ArrayList questionArrList=new ArrayList ();
- string[][] answer;
- private void Form2_Load(object sender, EventArgs e)
- {
- answerArr = new int[][] { new int[] { -3, 1 }, new int[] { -2, 2, 0 }, new int[] { 2, 6, 0 }, new int[] { 0,-4, -3 }, new int[] { -2,0},
- new int[]{1,4,3,0},new int[]{5,0},new int[]{-3,0},new int[]{3,0},new int[]{4,2,0},new int[]{-4,-3,0},new int[]{-3,3,0},new int[]{1,-1},
- new int[]{0,-1},new int[]{-8,-6,-3,-3},new int[]{0,-1},new int[]{-2,-4,-8},new int[]{2,2,0},new int[]{3,5,7,0}
- };
- //以下添加问题
- questionArrList.Add("1:您的性别是?");
- questionArrList.Add("2:你的居住地是?");
- questionArrList.Add("3:请选择:");
- questionArrList.Add("4:请选择:");
- questionArrList.Add("5:你是百万富翁吗?(可支配流动资金>100万人民币)");
- questionArrList.Add("6:请选择符合你的情况:");
- questionArrList.Add("7:你有和配偶住在一起吗?");
- questionArrList.Add("8:您经常伏案工作吗?");
- questionArrList.Add("9:您经常从事体力劳动吗?");
- questionArrList.Add("10:您每星期进行球类、游泳、跑步等运动多少次?");
- questionArrList.Add("11:您的睡眠情况是:");
- questionArrList.Add("12:你的生活状态符合以下哪种情况?");
- questionArrList.Add("13:您经常感到快乐吗?");
- questionArrList.Add("14:您去年因一次交通违章受罚吗?");
- questionArrList.Add("15:您的抽烟量是?(扣除分给别人的)");
- questionArrList.Add("16:平均每天喝白酒50毫升以上");
- questionArrList.Add("17:您的标准体重符合以下那种情况?(标准体重=身高-105)Kg");
- questionArrList.Add("18:下列情况哪种符合您的情况?");
- questionArrList.Add("19:请选择:");
- //以下添加答案
- answer = new string[][] {
- new string[] { "男性", "女性" },
- new string[] { "100万以上大城市", "人口少于1万人的小镇或农村"},
- new string[]{"祖父母或外祖父母中有1位活到85岁","4位祖辈都活到80岁"},
- new string[]{"以下都没有","父母有1人在50岁以前死于中风或心脏病","直系亲属中有50岁前得癌或心脏不正常或自幼就有糖尿病"},
- new string[]{"是","否"},
- new string[]{"大学毕业","大学毕业且65岁仍在工作","未大学毕业,不过65岁仍在工作","没有大学毕业,65岁也不再工作"},
- new string[]{"有","没有"},
- new string[]{"是的","没有或很少"},
- new string[]{"是的","没有或很少"},
- new string[]{"5次及以上","2-3次","没有或很少"},
- new string[]{"差不多每晚超过10个小时","睡眠经常不好","其它"},
- new string []{"经常紧张、易怒、性急","感到生活很轻松,工作应付自如","不好说"},
- new string[]{"是的","不是"},
- new string[]{"没有","有"},
- new string[]{"2包及其以上","1-2包","1包以下","我不抽烟"},
- new string []{"没有","有"},
- new string []{"超过标准5公斤","超过15公斤","超过25公斤"},
- new string []{"我已40多岁(男性)且每年体检一次","我每年妇科体检2次","其它"},
- new string []{"我今年30-40岁","我今年40-50岁","我超过70岁啦","其他"}
- };
- lblQuestion.Text = questionArrList[0].ToString ();
- //初始化第一个选择题的答案
- label1.Text = answer[0][0].ToString();
- label2.Text = answer[0][1].ToString();
- label3.Text = "";
- label4.Text = "";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //下一题时清空各个选项答案
- label1.Text = "";
- label2.Text = "";
- label3.Text = "";
- label4.Text = "";
- //判断是否已经完成全部答题
- if (questionIndex >= questionArrList.Count-1)
- {
- //处理第一个选项被选择时
- try
- {
- if (rb0.Checked)
- {
- lifespan += (int)answerArr[questionIndex][0];
- }
- //处理第二个选项被选择时
- if (rb1.Checked)
- {
- lifespan += (int)answerArr[questionIndex][1];
- }
- if (rb2.Checked)
- {
- lifespan += (int)answerArr[questionIndex][2];
- }
- if (rb3.Checked)
- {
- lifespan += (int)answerArr[questionIndex][3];
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("该项没有内容,请重新选择!");
- for (int j = 0; j < answer[questionIndex].Length; j++)
- {
- switch (j)
- {
- case 0: label1.Text = answer[questionIndex][j].ToString();
- break;
- case 1: label2.Text = answer[questionIndex][j].ToString();
- break;
- case 2: label3.Text = answer[questionIndex][j].ToString();
- break;
- case 3: label4.Text = answer[questionIndex][j].ToString();
- break;
- default:
- MessageBox.Show("错误");
- break;
- }
- }
- return;
- }
- button1.Text = "完成";
- MessageBox.Show("您的预期寿命是:" + lifespan.ToString() + "岁。如果您对该结果不满意,请不要灰心丧气,从现在做起,改变不良生活习惯,戒烟、戒酒、正确进行身体锻炼、乐观地生活,您的寿命就会延长,生命的钥匙就在您自己手上。");
- #region
- //显示最后一道题
- lblQuestion.Text = questionArrList[questionIndex].ToString();
- for (int j = 0; j < answer[questionIndex].Length; j++)
- {
- switch (j)
- {
- case 0: label1.Text = answer[questionIndex][j].ToString();
- break;
- case 1: label2.Text = answer[questionIndex][j].ToString();
- break;
- case 2: label3.Text = answer[questionIndex][j].ToString();
- break;
- case 3: label4.Text = answer[questionIndex][j].ToString();
- break;
- default:
- MessageBox.Show("错误");
- break;
- }
- }
- #endregion
- }
- else
- {
- try
- {
- //处理第一个选项被选择时
- if (rb0.Checked)
- {
- lifespan += (int)answerArr[questionIndex][0];
- }
- //处理第二个选项被选择时
- if (rb1.Checked)
- {
- lifespan += (int)answerArr[questionIndex][1];
- }
- if (rb2.Checked)
- {
- lifespan += (int)answerArr[questionIndex][2];
- }
- if (rb3.Checked)
- {
- lifespan += (int)answerArr[questionIndex][3];
- }
- }
- catch (Exception e2)
- {
- MessageBox.Show("该项没有内容,请重新选择!");
- for (int j = 0; j < answer[questionIndex].Length; j++)
- {
- switch (j)
- {
- case 0: label1.Text = answer[questionIndex][j].ToString();
- break;
- case 1: label2.Text = answer[questionIndex][j].ToString();
- break;
- case 2: label3.Text = answer[questionIndex][j].ToString();
- break;
- case 3: label4.Text = answer[questionIndex][j].ToString();
- break;
- default:
- MessageBox.Show("错误");
- break;
- }
- }
- return;
- }
- questionIndex++;
- lblQuestion.Text = questionArrList[questionIndex].ToString();
- for (int j = 0; j < answer[questionIndex].Length; j++)
- {
- switch (j)
- {
- case 0: label1.Text = answer[questionIndex][j].ToString();
- break;
- case 1: label2.Text = answer[questionIndex][j].ToString();
- break;
- case 2: label3.Text = answer[questionIndex][j].ToString();
- break;
- case 3: label4.Text = answer[questionIndex][j].ToString();
- break;
- default:
- MessageBox.Show("错误");
- break;
- }
- }
- }//end else
- }
- private void menuItem1_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void menuItem2_Click(object sender, EventArgs e)
- {
- MessageBox.Show("作者:阿佛 2008-11-11");
- }
- }
- }
手机算命源码(Windows mobile SDK 5)
最新推荐文章于 2024-04-30 11:41:10 发布