c程序设计教程第二版李春葆课后编程题答案

上传人:工**** 文档编号:499584158 上传时间:2023-06-05 格式:DOCX 页数:62 大小:141.09KB
返回 下载 相关 举报
c程序设计教程第二版李春葆课后编程题答案_第1页
第1页 / 共62页
c程序设计教程第二版李春葆课后编程题答案_第2页
第2页 / 共62页
c程序设计教程第二版李春葆课后编程题答案_第3页
第3页 / 共62页
c程序设计教程第二版李春葆课后编程题答案_第4页
第4页 / 共62页
c程序设计教程第二版李春葆课后编程题答案_第5页
第5页 / 共62页
点击查看更多>>
资源描述

《c程序设计教程第二版李春葆课后编程题答案》由会员分享,可在线阅读,更多相关《c程序设计教程第二版李春葆课后编程题答案(62页珍藏版)》请在金锄头文库上搜索。

1、输入a,b求c = a + busing System;using System.Collections.Generic;using System.Text;namespace Proj2_1classProgram staticvoidMain(string args) int a, b, c;Console.Write(a:); a = int.Parse( Console.ReadLine();Console.Write(b:); b = int.Parse(Console.ReadLine(); c = a + b;Console.WriteLine(a+b=0, c); using

2、System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Proj2_2publicpartialclassForm1 : Form public Form1() InitializeComponent(); privatevoid button1_Click(object sender, EventArgs e) int a, b

3、, c; a = Convert.ToInt16(textBox1.Text); b = Convert.ToInt16(textBox2.Text); c = a + b; textBox3.Text = Convert.ToString(c); privatevoid Form1_Load(object sender, EventArgs e) privatevoid textBox2_TextChanged(object sender, EventArgs e) 强制转换P38using System;using System.Collections.Generic;using Syst

4、em.Text;namespace Proj3_1classProgram staticvoidMain(string args) int i=65,i1,i2;double d = 66.3456,d1,d2;char c = A,c1,c2;Console.WriteLine(i=0:d5,d=1:f,c=2, i, d, c); i1 = (int)d; /强制类型转换 d1 = i;/隐式类型转换 c1 = (char)i;/强制类型转换Console.WriteLine(i1=0:d5,d1=1:f,c1=2, i1, d1, c1); i2 = c; /隐式类型转换 d2 = (i

5、nt)d; /强制类型转换 c2 = (char)d; /强制类型转换Console.WriteLine(i2=0:d5,d2=1:f,c2=2, i2, d2, c2); 赋值两同窗信息数据,并在图中输出成果P44using System;namespace Proj3_2classProgram structStudent/类型声明应放在Main函数旳外面 publicint xh; /学号publicstring xm;/姓名publicstring xb;/性别publicint nl;/年龄publicstring bh;/班号 staticvoidMain(string args)

6、 Student s1,s2;/定义两个构造类型变量 s1.xh = 101; s1.xm = 李明; s1.xb = 男; s1.nl = 20; s1.bh = 07001;Console.WriteLine(学号:0,姓名:1,性别:2,年龄:3,班号:4, s1.xh, s1.xm, s1.xb, s1.nl, s1.bh); s2 = s1;/将构造变量s1赋给s2 s2.xh = 108; s2.xm = 王华;Console.WriteLine(学号:0,姓名:1,性别:2,年龄:3,班号:4, s2.xh, s2.xm, s2.xb, s2.nl, s2.bh); 声明枚举类型

7、color,给两成员赋值,定义三个变量,赋值运算输出相应值。P47using System;using System.Collections.Generic;using System.Text;namespace Proj3_3classProgram enumColor Red=5, Green, Blue, White=1, Black /类型声明应放在Main函数旳外面staticvoidMain(string args) Color c1, c2,c3;Console.WriteLine(Red=0,Green=1,Blue=2,White=3,Black=4,Color.Red,Co

8、lor.Green,Color.Blue,Color.White,Color.Black);Console.WriteLine(Red=0,Green=1,Blue=2,White=3,Black=4,(int)Color.Red,(int)Color.Green,(int)Color.Blue,(int)Color.White,(int)Color.Black); c1 = Color.Red; c2 = c1 + 1; c3 = c2 + 1;Console.WriteLine(c1=0,c2=1,c3=2, c1, c2,c3);Console.WriteLine(c1=0,c2=1,c

9、3=2, (int)c1, (int)c2,(int)c3); 位运算符运用P50using System;using System.Collections.Generic;using System.Text;namespace Proj3_4classProgram staticvoidMain(string args) byte b1, b2, b3; b1 = 10; b2 =(byte) b1;Console.WriteLine(b2); b3 = (byte)(b1 2);Console.WriteLine(b3); b1 = 3; b2 = 6; b3 = (byte)(b1 &

10、b2);Console.WriteLine(b3); b3 = (byte)(b1 b2);Console.WriteLine(b3); b3 = (byte)(b1 | b2);Console.WriteLine(b3); 输出常用数据类型所用字节数P52using System;using System.Collections.Generic;using System.Text;namespace Proj3_5classProgram staticvoidMain(string args) Console.WriteLine(byte类型所占字节数:0, sizeof(byte);Con

11、sole.WriteLine(char类型所占字节数:0, sizeof(char);Console.WriteLine(int类型所占字节数:0, sizeof(int);Console.WriteLine(float类型所占字节数:0, sizeof(float);Console.WriteLine(double类型所占字节数:0, sizeof(double);Console.WriteLine(decimal类型所占字节数:0, sizeof(decimal); 求字符串子串在主串旳位置P56using System;using System.Collections.Generic;u

12、sing System.Text;namespace Proj3_6classProgram staticvoidMain(string args) String mstr,sstr;Console.Write(输入主串:); mstr = Console.ReadLine();Console.Write(输入子串:); sstr = Console.ReadLine();Console.WriteLine(主串长度=0,子串长度=1, mstr.Length, sstr.Length);if (String.Compare(mstr, sstr) != 0)Console.WriteLine(位置:0, mstr.IndexOf(sstr);elseConsole.WriteLine(两个字符串相似); DataTime构造旳使用P59using System;names

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号