[计算机软件及应用]高级程序设计C第八章ppt课件.ppt

上传人:牧羊曲112 文档编号:2047747 上传时间:2023-01-03 格式:PPT 页数:40 大小:2.85MB
返回 下载 相关 举报
[计算机软件及应用]高级程序设计C第八章ppt课件.ppt_第1页
第1页 / 共40页
[计算机软件及应用]高级程序设计C第八章ppt课件.ppt_第2页
第2页 / 共40页
[计算机软件及应用]高级程序设计C第八章ppt课件.ppt_第3页
第3页 / 共40页
[计算机软件及应用]高级程序设计C第八章ppt课件.ppt_第4页
第4页 / 共40页
[计算机软件及应用]高级程序设计C第八章ppt课件.ppt_第5页
第5页 / 共40页
点击查看更多>>
资源描述

《[计算机软件及应用]高级程序设计C第八章ppt课件.ppt》由会员分享,可在线阅读,更多相关《[计算机软件及应用]高级程序设计C第八章ppt课件.ppt(40页珍藏版)》请在三一办公上搜索。

1、2023/1/3,1,高级程序设计,授课教师:祁长兴,C#,第八章:常用类,2023/1/3,2,常用类,2023/1/3,3,Math,静态字段PIE静态方法整数运算初等函数三角函数,Abs():求绝对值Ceiling()求大于等于指定数值的最小整数Floor()求小于或等于指定数值的最大整数Round()对数值进行四舍五入,Exp():求e的指数幂Pow()指数函数Log()对数函数Lg10()求以10为底的对数Sqrt()求平方根,Sin():求正弦函数Cos()求余弦函数Tan()求正切函数。,2023/1/3,4,static void Main(string args)double

2、 a=-1.2;int k=-1,d;double b,c;int i;b=Math.Abs(a);Console.WriteLine(Abs(a)=0,b);d=Math.Abs(k);Console.WriteLine(Abs(k)=0,d);c=Math.Ceiling(1.2);,Console.WriteLine(Ceiling(1.2)=0,c);c=Math.Floor(1.2);Console.WriteLine(Floor(1.2)=0,c);c=Math.Round(1.5);Console.WriteLine(Round(1.5)=0,c);c=Math.Round(1.

3、2);Console.WriteLine(Round(1.2)=0,c);b=Math.Exp(2.1);Console.WriteLine(Exp(2.1)=0,b);b=Math.Pow(2,3);Console.WriteLine(Pow(2,3)=0,b);b=Math.Log(10);Console.WriteLine(Log(10)=0,b);b=Math.Log10(10);Console.WriteLine(Log10(10)=0,b);b=Math.Sqrt(9);Console.WriteLine(Sqrt(9)=0,b);Console.ReadLine();,2023/

4、1/3,5,Math,DemoP8-1,2023/1/3,6,string,构造函数与赋值 1。直接赋值:string s1=“software”2。构造函数赋值:string(char,int)string(char)string(char,int,int),2023/1/3,7,static void Main(string args)string s1=helloworld!;Console.WriteLine(s1=0,s1);string s2=new string(a,5);Console.WriteLine(s2=0,s2);char s3=new charm,i,c,r,o,s

5、,o,f,t;string s4=new string(s3);string s5=new string(s3,1,4);Console.WriteLine(s3=0,s3);Console.WriteLine(s4=0,s4);Console.WriteLine(s5=0,s5);Console.ReadLine();,2023/1/3,8,String,获取字符string char:索引函数string char:char ToChayArray()char ToChayArray(int int)/起始位置,复制的长度 CopyTo(int,char,int,int)/起始位置,目标数

6、组,指定数组起始位置,复制的长度,2023/1/3,9,static void Main(string args)string s1=Microsoft!;char chs1=s1.ToCharArray();char chs2=s1.ToCharArray(5,4);Console.WriteLine(new string(chs1);Console.WriteLine(new string(chs2);char chs=new char20;Microsoft.CopyTo(0,chs,0,9);Windows2003.CopyTo(0,chs,10,7);Console.WriteLin

7、e(new string(chs);Console.ReadLine();,2023/1/3,10,字符查找,int IndexOf(char)int IndexOf(char,int)int IndexOf(char,int,int)int LastIndexOf(char,int,int)int IndexOfAny(char),static void Main(string args)string s1=沈阳师范大学软件学院;int pos=s1.IndexOf(软);Console.WriteLine(pos=0,pos);Console.ReadLine();,2023/1/3,11

8、,public class SearchCharSample static void Main()bool bFail=true;string sName;char illChars=,#,$,%,2023/1/3,12,练习,输入一个字符串,求其中字符e出现的次数,2023/1/3,13,using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1 class Program static void Main(string args

9、)/string s1=miscrosoft is a big company and it is super enterprise.I study from it and want to enter;s1=Console.ReadLine();int i=0,j=0,pos=0;while(pos=0)pos=s1.IndexOf(e,j);if(pos=0)i+;j=pos+1;Console.WriteLine(i=0,i);Console.ReadLine();,2023/1/3,14,字符串填充与修剪,string PadLeft(int)string PadLeft(int cha

10、r)string Trim()string Trim(char)/TrimStart(),TrimEnd(),2023/1/3,15,static void Main(string args)string s1=Microsoft,s2,s3,s4;s2=s1.PadLeft(12,);s3=s2.PadRight(14,);s4=s3.PadLeft(16,*);s4=s4.PadRight(18,*);Console.WriteLine(0,s4);Console.ReadLine();,2023/1/3,16,String,获取子串SubString查找子串IndexOf/LastInd

11、exOfStartsWith/EndWith插入/删除子串Insert/Remove替换子串 Replace,2023/1/3,17,练习,输入一个字符串,去掉其中子串err,2023/1/3,18,static void Main(string args)/string s1=Microsoft is are a big company and the leader in it is are super man!;s1=Console.ReadLine();int pos=0;while(pos=0)pos=s1.IndexOf(are);if(pos=0)s1=s1.Substring(0

12、,pos)+s1.Substring(pos+are.Length);Console.WriteLine(0,s1);Console.ReadLine();问题是?=Microsoft is are a big company and the leader in it is aarere super man!;,2023/1/3,19,static void Main(string args)string s1=Microsoft is are a big company and the leader in it is aarere super man!,s2;s2=;int pos=0;wh

13、ile(pos=0)pos=s1.IndexOf(are);if(pos=0)s2=s2+s1.Substring(0,pos);s1=s1.Substring(pos+are.Length);s2+=s1;Console.WriteLine(0,s2);Console.ReadLine();,2023/1/3,20,static void Main(string args)string s1=Microsoft is are a big company and the leader in it is aarere super man!,s2;s2=s1.Replace(are,);Conso

14、le.WriteLine(0,s2);Console.ReadLine();,2023/1/3,21,Remove()Insert(),2023/1/3,22,String,格式化字符串Format解析字符串Parse/TryParseDemo,2023/1/3,23,StringBuilder,构造函数性能优化 Demo,2023/1/3,24,常用数据结构类,DateTime:日期/时间你会如何设计这个类?ArrayList:链表你会如何设计这个类?Demo,2023/1/3,25,String,编写程序,输入一个字符串,求串中包含字符串“am”的个数。,2023/1/3,26,stati

15、c void Main(string args)string s1=iamamiddleschoolstudentndiamaboy!iamateacher;int j=0,k=0,i=0;while(i=0)i=s1.IndexOf(am,k);Console.WriteLine(i=0,i);if(i=0)j+;k=i+am.Length;Console.WriteLine(s1=0,j);Console.ReadLine();,2023/1/3,27,String,判断输入的字符串是否为有效身份证号码(18位,第7位开始,连续8个数字为日期即可),2023/1/3,28,class Pr

16、ogram static void Main(string args)string s1=Console.ReadLine();if(s1.Length!=18)Console.WriteLine(无T效的?身?份证号?码?);else string s2=s1.Substring(6,8);s2=s1.Substring(6,4)+-+s1.Substring(10,2)+-+s1.Substring(12,2);try DateTime d1=DateTime.Parse(s2);Console.WriteLine(有瓺效的?身?份证号?码?);catch(Exception)Consol

17、e.WriteLine(无T效的?身?份证号?码?);finally Console.ReadLine();,2023/1/3,29,常用类,Windows窗体和控件,2023/1/3,30,Windows窗体和控件,ColorSize/PointSizeF/PointF Demo,2023/1/3,31,Windows窗体和控件,Form构造函数属性方法事件 Demo,2023/1/3,32,Windows窗体和控件,Control属性方法事件,2023/1/3,33,Windows窗体和控件,2023/1/3,34,Windows窗体和控件,模态 ShowDialog非模态 Show常用事

18、件 Load FormClosing FormClosed。,2023/1/3,35,Windows窗体和控件,private void Form1_FormClosing(object sender,FormClosingEventArgs e)MessageBox.Show(Form1_FormClosing);private void Form1_FormClosed(object sender,FormClosedEventArgs e)MessageBox.Show(Form1_FormClosed);private void Form1_Activated(object sende

19、r,EventArgs e)/MessageBox.Show(Form1_Activated);private void Form1_Deactivate(object sender,EventArgs e)/MessageBox.Show(Form1_Deactivate);private void Form1_SizeChanged(object sender,EventArgs e)MessageBox.Show(Form1_SizeChanged);private void Form1_LocationChanged(object sender,EventArgs e)MessageBox.Show(Form1_LocationChanged);,2023/1/3,36,Windows窗体和控件,按钮控件Button文本标签Label Demo,2023/1/3,37,Windows窗体和控件,输入控件TextBox/RichTextBoxCheckBox/RadioButtonComboBox/ListBox Demo,2023/1/3,38,总结,2023/1/3,39,习题,P203选择题:1,2,3,4,5,6,2023/1/3,40,The End!,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号