面向对象程序设计实验报告(2)
}
}
(10)分析程序,写出程序的运行结果,并上机进行验证。
using System;
namespace _1
{
class Program
{
static void Main(string[] args)
{
int odd = 0, even = 0;
面向对象程序设计实验报告
int[] array = new int[] { 0, 4, 7, 8, 9, 10, 14, 17, 19, 24, 56 };
foreach (int i in array)
{
if (i % 2 == 0)
even++;
else
odd++;
}
Console.WriteLine("{0}个奇数,{1}个偶数", odd, even);
}
}
}
(11)分析程序,写出程序的运行结果,并上机进行验证。
using System;
public class TestDoWhile
{
public static void Main ()
{
int x;
int y = 0;
do
{
x = y++;
Console.WriteLine(x);
}
while(y < 5);
}
}
(12)分析程序,写出程序的运行结果,并上机进行验证。
using System;
namespace _1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("---break---");
for (int i = 0; i < 10; i++)
{
if (i == 5) break;
Console.WriteLine("i is " + i);
}
Console.WriteLine("---continue---");
for (int i = 0; i < 10; i++)
面向对象程序设计实验报告
{
if (i == 5) continue;
Console.WriteLine("i is " + i);
}
Console.Read();
}
}
}
题目二:程序编写
(1) 编写程序,定义一个包括学生基本资料的结构类型数据(要求包括学号、姓名、
性别、年龄、家庭住址等),并对其进行测试。
(2) 编写程序,将一年中的12个月建立一个枚举类型,并对其进行测试。
(3) 编写程序,使用int类型数据进行装箱与拆箱转换。
(4) 编写程序,分别用for、while、do…while语句实现求前n个自然数之和。
(5) 编写程序,输出九九乘法表。
面向对象程序设计实验报告
实验三 C#面向对象程序设计
一、实验目的
1.理解C#语言是如何体现面向对象编程基本思想。
2.掌握类对象的定义。
3.了解类的封装方法,以及如何创建类和对象。
4.了解成员变量和成员方法的特性。
5.掌握静态成员的用法。
二、实验要求
1. 分析程序,上机验证结果。
2. 写出程序,并调试程序,要给出测试数据和实验结果。
3. 整理上机步骤,总结经验和体会。
4. 完成实验日志和上交程序。
三、实验内容
题目一:程序分析
(1)分析下面两个程序,确定那个程序好,说明理由。
程序要求:定义一个圆类,计算圆的面积和周长。
程序1:
public class circle
{
public static void Main()
{
double radium, delimeter, square;
const double pai = 3.1415926;
radium = Convert.ToInt32(Console.ReadLine());
delimeter = 2 * pai * radium;
square = pai * pai * radium;
Console.WriteLine("delimeter={0},square={1}", delimeter, square);
Console.ReadLine();
}
}
程序2:
public class circle
{
double delimeter, square;
const double pai = 3.1415926;
public void calculate(double rad)
{
delimeter = 2 * pai * rad;
square = pai * pai * rad;
Console.WriteLine("delimeter={0},square={1}",delimeter,square);
面向对象程序设计实验报告
public static void Main()
{
double radium;
circle cir = new circle();
radium = Convert.ToInt32(Console.ReadLine());
cir.calculate(radium);
Console.ReadLine();
}
}
(2)分析程序,写出程序的运行结果,并上机进行验证。
Using System;
public class students
{
string id,name;
int age;
public students(string id,string name,int age )
{
this.id = id;
= name;
this.age = age;
}
public void Display()
{
Console.WriteLine("id={0},name={1},age={2}",id,name,age);
}
public static void Main()
{
//string id, name;
//int age;
students stu = new students("0001","zhangsan",16);
stu.Display();
Console.ReadLine();
}
}
(3)分析程序,写出程序的运行结果,并上机进行验证。
public class Date
{
private int Year, Month, Day;
public Date(int Year, int Month,int Day)
{
this.Year=Year;
this.Month=Month;
this.Day=Day;
面向对象程序设计实验报告
public Date(System.DateTime dt)
{
Year = dt.Year;
Month = dt.Month;
Day = dt.Day;
}
public void DisplayDate()
{
Console.WriteLine("{0}年{1}月{2}日",Year,Month,Day);
}
}
public class Tester
{
public static void Main()
{
System.DateTime currentTime=System.DateTime.Now;
Date dt=new Date(2008,7,18);
dt.DisplayDate();
Date dt2 = new Date(currentTime);
dt2.DisplayDate();
Console.ReadLine();
}
}
题目二:程序编写
(1) 实现一个包含类属性方法的简单加法程序,并能显示结果。
(2) 实现一个Person类,要求:属性包含姓名、年龄、身份证号、工作、工资等,并
显示各属性的值。
面向对象程序设计实验报告
实验四 C#面向对象程序设计(二)
一、实验目的
1. 掌握构造函数和析构函数的含义与作用、定义方式和实现,能够根据要求正确定义和重载构造函数。能够根据给定的要求定义类并实现类的成员函数。
2. 理解类的成员的访问控制的含义,公有、私有和保护成员的区别。
3. 掌握参数传递的用法。
4. 掌握属性的作用和使用。
二、实验要求
1. 分析程序,上机验证结果。
2. 写出程序,并调试程序,要给出测试数据和实验结果。
3. 整理上机步骤,总结经验和体会。
4. 完成实验日志和上交程序。
三、实验内容
题目一:程序分析
(1) 分析程序,写出程序的运行结果,并上机进行验证,然后回答后面问题。 public class BankAccount
{
static int totalAccountNumber=0;
string BankAccountId;
double initialDepositAmount = 0.00;
public BankAccount(string myId)
{
相关推荐:
- [教育文库]夜场KTV服务员的岗位职责及工作流程[1]
- [教育文库]企划、网络、市场绩效考核方案
- [教育文库]学党史、知党情、强党性--“党的基本理
- [教育文库]2016年高考物理大一轮总复习(江苏专版
- [教育文库]干部廉洁自律自查自纠的报告
- [教育文库]2010年北京大学心理学系拟录取硕士研究
- [教育文库]资金时间价值练习题及答案
- [教育文库]保护环境的心得体会
- [教育文库]英语角内容:英语趣味小知识
- [教育文库]档案收集与管理工作通知
- [教育文库]劳动规章制度范本范本
- [教育文库]高考物理一轮复习课后限时作业1运动的
- [教育文库]机械工艺夹具毕业设计195推动架设计说
- [教育文库]通用技术教学比赛说课稿2
- [教育文库]2018年四年级英语下册 Module 7 Unit 2
- [教育文库]第2章 宽带IP网络的体系结构
- [教育文库]九年级化学第五单元课题3《根据化学方
- [教育文库]小学英语六年级情态动词用法归纳
- [教育文库]甲级单位编制窑井盖项目可行性报告(立
- [教育文库]2016-2021年中国城市规划行业全景调研
- 高考英语听力十大场景词汇总结
- 全省领导班子思想政治建设座谈会会议精
- 人教版新课标高一英语提优竞赛试题 下
- 江西省2014年生物中考试题
- 长沙镇食品药品安全事故应急预案
- 《金刚石、石墨和C60》片段教学设计
- 福州教育学院(王旭东)
- 基于EDA音乐播放器的设计
- 9、古诗两首《夜书所见》《九月九日忆
- 小学语文课外阅读有效策略探讨
- 贵州文化产业发展成支柱产业的问卷调查
- 膀胱类癌的诊治体会(附3例报告)
- 发动机积碳产生的原因
- Configuring Code Composer Studio for
- 学生良好的心理素质如何培养点滴谈
- 46 电沉积法制备锂离子电池用硅-锂薄膜
- 美舍雅阁公司管理中各部门职责
- 去壳剥皮的小妙招
- 六自由度运动平台的仿真研究
- Pride and Prejudice(傲慢与偏见)




