实验六 继承定义与使用

实验六 继承定义与使用

实验时间 2018-9-28

1、实验目的与要求

(1) 理解继承的定义;

(2) 掌握子类的定义要求

(3) 掌握多态性的概念及用法;

(4) 掌握抽象类的定义及用途;

(5) 掌握类中4个成员访问权限修饰符的用途;

(6) 掌握抽象类的定义方法及用途;

(7)掌握Object类的用途及常用API;

(8) 掌握ArrayList类的定义方法及用法;

(9) 掌握枚举类定义方法及用途。

2、实验内容和步骤

实验1: 导入第5章示例程序,测试并进行代码注释。

测试程序1:

在elipse IDE中编辑、调试、运行程序5-1 (教材152页-153页) ;

掌握子类的定义及用法;

结合程序运行结果,理解并总结OO风格程序构造特点,理解Employee和Manager类的关系子类的用途,并在代码中添加注释。

测试实验结果如下:

插入此程序的代码并对其进行注释,进行更深一步的理解

ManagerTest

package inheritance;

/
public class ManagerTest
{
   public static void main(String[] args)
   {
      // 构建管理者对象
      Manager boss = new Manager("Carl Cracker", 80000, 1987, 12, 15);
      boss.setBonus(5000);

      Employee[] staff = new Employee[3];//定义一个包含3个雇员的数组

      // 用管理者和员工对象填充员工数组

      staff[0] = boss;
      staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
      staff[2] = new Employee("Tommy Tester", 40000, 1990, 3, 15);

      // 打印关于所有员工对象的信息
      for (Employee e : staff)
         System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
      //输出每个人的薪水
   }

}

  Manager

package inheritance;

public class Manager extends Employee
{
   private double bonus;

   /**
    * @param name the employee‘s name
    * @param salary the salary
    * @param year the hire year
    * @param month the hire month
    * @param day the hire day
    */
   public Manager(String name, double salary, int year, int month, int day)
   {
      super(name, salary, year, month, day);
      bonus = 0;
   }

   public double getSalary()
   {
      double baseSalary = super.getSalary();
      return baseSalary + bonus;
   }

   public void setBonus(double b)
   {
      bonus = b;
   }
}

Emloyee:

package inheritance;

import java.time.*;

public class Employee
{
   private String name;
   private double salary;
   private LocalDate hireDay;

   public Employee(String name, double salary, int year, int month, int day)
   {
      this.name = name;
      this.salary = salary;
      hireDay = LocalDate.of(year, month, day);
   }

   public String getName()
   {
      return name;
   }

   public double getSalary()
   {
      return salary;
   }

   public LocalDate getHireDay()
   {
      return hireDay;
   }

   public void raiseSalary(double byPercent)
   {
      double raise = salary * byPercent / 100;
      salary += raise;
   }
}
package inheritance;

import java.time.*;

public class Employee
{
   private String name;
   private double salary;
   private LocalDate hireDay;

   public Employee(String name, double salary, int year, int month, int day)
   {
      this.name = name;
      this.salary = salary;
      hireDay = LocalDate.of(year, month, day);
   }

   public String getName()
   {
      return name;
   }

   public double getSalary()
   {
      return salary;
   }

   public LocalDate getHireDay()
   {
      return hireDay;
   }

   public void raiseSalary(double byPercent)
   {
      double raise = salary * byPercent / 100;
      salary += raise;
   }
}

子类的定义:在有继承关系的类中extends前面的类则是子类。

超类和子类都是Java程序员常用的两个类。

测试程序2:

编辑、编译、调试运行教材PersonTest程序(教材163页-165页);

掌握超类的定义及其使用要求;

掌握利用超类扩展子类的要求;

在程序中相关代码处添加新知识的注释。

超类:如果在程序中没有明确的之处超类,Object就是被认为是这个类的超类,如:Public class Employee extebds Object.在java中,每个类都是Object类扩展而来的。当然也可以使用Object类型的变量引用任何类型的对象。

超类扩展子类的要求

代码的注释:

package abstractClasses;

import java.time.*;

public class Employee extends Person
{
   private double salary;
   private LocalDate hireDay;

   public Employee(String name, double salary, int year, int month, int day)
   {
      super(name);
      this.salary = salary;
      hireDay = LocalDate.of(year, month, day);
   }

   public double getSalary()
   {
      return salary;
   }

   public LocalDate getHireDay()
   {
      return hireDay;
   }

   public String getDescription()
   {
      return String.format("an employee with a salary of $%.2f", salary);
   }

   public void raiseSalary(double byPercent)
   {
      double raise = salary * byPercent / 100;
      salary += raise;
   }
}
package abstractClasses;

/**
 * This program demonstrates abstract classes.
 * @version 1.01 2004-02-21
 * @author Cay Horstmann
 */
public class PersonTest
{
   public static void main(String[] args)
   {
      Person[] people = new Person[2];

      // 用Student和Employee对象填充人员数组
      people[0] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
      people[1] = new Student("Maria Morris", "computer science");

      // 打印所有person对象的名称和描述
      for (Person p : people)
         System.out.println(p.getName() + ", " + p.getDescription());
   }
}
package abstractClasses;

public class Student extends Person
{
   private String major;

   /**
    * @param nama the student‘s name
    * @param major the student‘s major
    */
   public Student(String name, String major)
   {
      // 将n传递给父类函数
      super(name);
      this.major = major;
   }

   public String getDescription()
   {
      return "a student majoring in " + major;
   }
}

测试程序3:

编辑、编译、调试运行教材程序5-8、5-9、5-10,结合程序运行结果理解程序(教材174页-177页);

掌握Object类的定义及用法;

在程序中相关代码处添加新知识的注释。

Employee.java:

package equals;

import java.time.*;
import java.util.Objects;

public class Employee
{
   private String name;
   private double salary;
   private LocalDate hireDay;

   public Employee(String name, double salary, int year, int month, int day)
   {
      this.name = name;
      this.salary = salary;
      hireDay = LocalDate.of(year, month, day);
   }

   public String getName()
   {
      return name;
   }

   public double getSalary()
   {
      return salary;
   }

   public LocalDate getHireDay()
   {
      return hireDay;
   }

   public void raiseSalary(double byPercent)
   {
      double raise = salary * byPercent / 100;
      salary += raise;
   }

   public boolean equals(Object otherObject)
   {
      // 看看这些对象是否相同
      if (this == otherObject) return true;

      // 如果显式参数为空,则必须返回false
      if (otherObject == null) return false;

      // 如果类不匹配,它们就不能相等
      if (getClass() != otherObject.getClass()) return false;

      // 现在我们知道otherObject是一个非空雇员
      Employee other = (Employee) otherObject;

      // 测试字段是否具有相同的值
      return Objects.equals(name, other.name) && salary == other.salary && Objects.equals(hireDay, other.hireDay);
   }

   public int hashCode()
   {
      return Objects.hash(name, salary, hireDay);
   }

   public String toString()
   {
      return getClass().getName() + "[name=" + name + ",salary=" + salary + ",hireDay=" + hireDay
            + "]";
   }
}

Manager.java:

package equals;

public class Manager extends Employee//子类Manager继承父类Employee
{
   private double bonus;

   public Manager(String name, double salary, int year, int month, int day)
   {
      super(name, salary, year, month, day);
      bonus = 0;
   }

   public double getSalary()
   {
      double baseSalary = super.getSalary();
      return baseSalary + bonus;
   }

   public void setBonus(double bonus)
   {
      this.bonus = bonus;
   }

   public boolean equals(Object otherObject)
   {
      if (!super.equals(otherObject)) return false;
      Manager other = (Manager) otherObject;
      // super.equals检查这个和其他属于同一个类
      return bonus == other.bonus;
   }

   public int hashCode()
   {
      return java.util.Objects.hash(super.hashCode(), bonus);
   }

   public String toString()
   {
      return super.toString() + "[bonus=" + bonus + "]";
   }
}

Equals.java:

package equals;

/**
 * This program demonstrates the equals method.
 * @version 1.12 2012-01-26
 * @author Cay Horstmann
 */
public class EqualsTest
{
   public static void main(String[] args)
   {
      Employee alice1 = new Employee("Alice Adams", 75000, 1987, 12, 15);
      Employee alice2 = alice1;
      Employee alice3 = new Employee("Alice Adams", 75000, 1987, 12, 15);
      Employee bob = new Employee("Bob Brandson", 50000, 1989, 10, 1);

      System.out.println("alice1 == alice2: " + (alice1 == alice2));

      System.out.println("alice1 == alice3: " + (alice1 == alice3));

      System.out.println("alice1.equals(alice3): " + alice1.equals(alice3));

      System.out.println("alice1.equals(bob): " + alice1.equals(bob));

      System.out.println("bob.toString(): " + bob);

      Manager carl = new Manager("Carl Cracker", 80000, 1987, 12, 15);
      Manager boss = new Manager("Carl Cracker", 80000, 1987, 12, 15);
      boss.setBonus(5000);
      System.out.println("boss.toString(): " + boss);
      System.out.println("carl.equals(boss): " + carl.equals(boss));
      System.out.println("alice1.hashCode(): " + alice1.hashCode());
      System.out.println("alice3.hashCode(): " + alice3.hashCode());
      System.out.println("bob.hashCode(): " + bob.hashCode());
      System.out.println("carl.hashCode(): " + carl.hashCode());
   }
}
package equals;

/**
 * This program demonstrates the equals method.
 * @version 1.12 2012-01-26
 * @author Cay Horstmann
 */
public class EqualsTest
{
   public static void main(String[] args)
   {
      Employee alice1 = new Employee("Alice Adams", 75000, 1987, 12, 15);
      Employee alice2 = alice1;
      Employee alice3 = new Employee("Alice Adams", 75000, 1987, 12, 15);
      Employee bob = new Employee("Bob Brandson", 50000, 1989, 10, 1);

      System.out.println("alice1 == alice2: " + (alice1 == alice2));

      System.out.println("alice1 == alice3: " + (alice1 == alice3));

      System.out.println("alice1.equals(alice3): " + alice1.equals(alice3));

      System.out.println("alice1.equals(bob): " + alice1.equals(bob));

      System.out.println("bob.toString(): " + bob);

      Manager carl = new Manager("Carl Cracker", 80000, 1987, 12, 15);
      Manager boss = new Manager("Carl Cracker", 80000, 1987, 12, 15);
      boss.setBonus(5000);
      System.out.println("boss.toString(): " + boss);
      System.out.println("carl.equals(boss): " + carl.equals(boss));
      System.out.println("alice1.hashCode(): " + alice1.hashCode());
      System.out.println("alice3.hashCode(): " + alice3.hashCode());
      System.out.println("bob.hashCode(): " + bob.hashCode());
      System.out.println("carl.hashCode(): " + carl.hashCode());
   }
}

测试程序4:

在elipse IDE中调试运行程序5-11(教材182页),结合程序运行结果理解程序;

掌握ArrayList类的定义及用法;

在程序中相关代码处添加新知识的注释。

插入程序相关代码

ArrayList.java:

package arrayList;

import java.util.*;

/**
 * This program demonstrates the ArrayList class.
 * @version 1.11 2012-01-26
 * @author Cay Horstmann
 */
public class ArrayListTest
{
   public static void main(String[] args)
   {
      // 用三个Employee对象填充staff数组列表
      ArrayList<Employee> staff = new ArrayList<>();

      staff.add(new Employee("Carl Cracker", 75000, 1987, 12, 15));
      staff.add(new Employee("Harry Hacker", 50000, 1989, 10, 1));
      staff.add(new Employee("Tony Tester", 40000, 1990, 3, 15));

      // 把每个人的薪水提高5%
      for (Employee e : staff)
         e.raiseSalary(5);

      // 打印所有Employee对象的信息
      for (Employee e : staff)
         System.out.println("name=" + e.getName() + ",salary=" + e.getSalary() + ",hireDay="
               + e.getHireDay());
   }
}

Employee.java:

package arrayList;

import java.time.*;

public class Employee
{
   private String name;
   private double salary;
   private LocalDate hireDay;

   public Employee(String name, double salary, int year, int month, int day)
   {
      this.name = name;
      this.salary = salary;
      hireDay = LocalDate.of(year, month, day);
   }

   public String getName()
   {
      return name;
   }

   public double getSalary()
   {
      return salary;
   }

   public LocalDate getHireDay()
   {
      return hireDay;
   }

   public void raiseSalary(double byPercent)
   {
      double raise = salary * byPercent / 100;
      salary += raise;
   }
}
package arrayList;

import java.time.*;

public class Employee
{
   private String name;
   private double salary;
   private LocalDate hireDay;

   public Employee(String name, double salary, int year, int month, int day)
   {
      this.name = name;
      this.salary = salary;
      hireDay = LocalDate.of(year, month, day);
   }

   public String getName()
   {
      return name;
   }

   public double getSalary()
   {
      return salary;
   }

   public LocalDate getHireDay()
   {
      return hireDay;
   }

   public void raiseSalary(double byPercent)
   {
      double raise = salary * byPercent / 100;
      salary += raise;
   }
}

程序测试结果如下:

测试程序5:

编辑、编译、调试运行程序5-12(教材189页),结合运行结果理解程序;

掌握枚举类的定义及用法;

在程序中相关代码处添加新知识的注释。

插入实例程序的代码:

package enums;

import java.util.*;

/**
 * This program demonstrates enumerated types.
 * @version 1.0 2004-05-24
 * @author Cay Horstmann
 */
public class EnumTest
{
   public static void main(String[] args)
   {
      Scanner in = new Scanner(System.in);
      System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
      String input = in.next().toUpperCase();
      Size size = Enum.valueOf(Size.class, input);
      System.out.println("size=" + size);
      System.out.println("abbreviation=" + size.getAbbreviation());
      if (size == Size.EXTRA_LARGE)
         System.out.println("Good job--you paid attention to the _.");
   }
}

enum Size
{
   SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");

   private Size(String abbreviation) { this.abbreviation = abbreviation; }
   public String getAbbreviation() { return abbreviation; }

   private String abbreviation;
}

测试结果如下:

实验2:编程练习1

定义抽象类Shape:

属性:不可变常量double PI,值为3.14;

方法:public double getPerimeter();public double getArea())。

让Rectangle与Circle继承自Shape类。

编写double sumAllArea方法输出形状数组中的面积和和double sumAllPerimeter方法输出形状数组中的周长和。

main方法中

1)输入整型值n,然后建立n个不同的形状。如果输入rect,则再输入长和宽。如果输入cir,则再输入半径。
2) 然后输出所有的形状的周长之和,面积之和。并将所有的形状信息以样例的格式输出。
3) 最后输出每个形状的类型与父类型,使用类似shape.getClass()(获得类型),shape.getClass().getSuperclass()(获得父类型);

思考sumAllArea和sumAllPerimeter方法放在哪个类中更合适?

输入样例:

3

rect

1 1

rect

2 2

cir

1

输出样例:

18.28

8.14

[Rectangle [width=1, length=1], Rectangle [width=2, length=2], Circle [radius=1]]

class Rectangle,class Shape

class Rectangle,class Shape

class Circle,class Shape

程序相关代码:

shape:

package shape;
import java.util.Scanner;
public class Test {
 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  System.out.println("个数");
  int a = in.nextInt();
  System.out.println("种类");
  String rect="rect";
        String cir="cir";
  Shape[] num=new Shape[a];
  for(int i=0;i<a;i++){
   String input=in.next();
   if(input.equals(rect)) {
   System.out.println("长和宽");
   int length = in.nextInt();
   int width = in.nextInt();
         num[i]=new Rectangle(width,length);
         System.out.println("Rectangle["+"length:"+length+"  width:"+width+"]");
         }
   if(input.equals(cir)) {
         System.out.println("半径");
      int radius = in.nextInt();
      num[i]=new Circle(radius);
      System.out.println("Circle["+"radius:"+radius+"]");
         }
         }
         Test c=new Test();
         System.out.println("求和");
         System.out.println(c.sumAllPerimeter(num));
         System.out.println(c.sumAllArea(num));

         for(Shape s:num) {
             System.out.println(s.getClass()+","+s.getClass().getSuperclass());
             }
         }

           public double sumAllArea(Shape score[])
           {
           double sum=0;
           for(int i=0;i<score.length;i++)
               sum+= score[i].getArea();
               return sum;
           }
           public double sumAllPerimeter(Shape score[])
           {
           double sum=0;
           for(int i=0;i<score.length;i++)
               sum+= score[i].getPerimeter();
               return sum;
           }
}

Test:

package shape;
import java.util.Scanner;
public class Test {
 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  System.out.println("个数");
  int a = in.nextInt();
  System.out.println("种类");
  String rect="rect";
        String cir="cir";
  Shape[] num=new Shape[a];
  for(int i=0;i<a;i++){
   String input=in.next();
   if(input.equals(rect)) {
   System.out.println("长和宽");
   int length = in.nextInt();
   int width = in.nextInt();
         num[i]=new Rectangle(width,length);
         System.out.println("Rectangle["+"length:"+length+"  width:"+width+"]");
         }
   if(input.equals(cir)) {
         System.out.println("半径");
      int radius = in.nextInt();
      num[i]=new Circle(radius);
      System.out.println("Circle["+"radius:"+radius+"]");
         }
         }
         Test c=new Test();
         System.out.println("求和");
         System.out.println(c.sumAllPerimeter(num));
         System.out.println(c.sumAllArea(num));

         for(Shape s:num) {
             System.out.println(s.getClass()+","+s.getClass().getSuperclass());
             }
         }

           public double sumAllArea(Shape score[])
           {
           double sum=0;
           for(int i=0;i<score.length;i++)
               sum+= score[i].getArea();
               return sum;
           }
           public double sumAllPerimeter(Shape score[])
           {
           double sum=0;
           for(int i=0;i<score.length;i++)
               sum+= score[i].getPerimeter();
               return sum;
           }
}

实验结果如下所示:

实验3: 编程练习2

编制一个程序,将身份证号.txt 中的信息读入到内存中,输入一个身份证号或姓名,查询显示查询对象的姓名、身份证号、年龄、性别和出生地。

插入程序代码:

Main :

package id1;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    private static ArrayList<Student> studentlist;
    public static void main(String[] args) {
        studentlist = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        File file = new File("D:/身份证号.txt");
        try {
            FileInputStream fis = new FileInputStream(file);
            BufferedReader in = new BufferedReader(new InputStreamReader(fis));
            String temp = null;
            while ((temp = in.readLine()) != null) {

                Scanner linescanner = new Scanner(temp);

                linescanner.useDelimiter(" ");
                String name = linescanner.next();
                String number = linescanner.next();
                String sex = linescanner.next();
                String year = linescanner.next();
                String province =linescanner.nextLine();
                Student student = new Student();
                student.setName(name);
                student.setnumber(number);
                student.setsex(sex);
                student.setyear(year);
                student.setprovince(province);
                studentlist.add(student);

            }
        } catch (FileNotFoundException e) {
            System.out.println("学生信息文件找不到");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("学生信息文件读取错误");
            e.printStackTrace();
        }
        boolean isTrue = true;
        while (isTrue) {

            System.out.println("1.按姓名查询");
            System.out.println("2.按身份证号查询");
            System.out.println("3.退出");
            int nextInt = scanner.nextInt();
            switch (nextInt) {
            case 1:
                System.out.println("请输入姓名");
                String studentname = scanner.next();
                int nameint = findStudentByname(studentname);
                if (nameint != -1) {
                    System.out.println("查找信息为:身份证号:"
                            + studentlist.get(nameint).getnumber() + "    姓名:"
                            + studentlist.get(nameint).getName() +"    性别:"
                            +studentlist.get(nameint).getsex()   +"    年龄:"
                            +studentlist.get(nameint).getyaer()+"  地址:"
                            +studentlist.get(nameint).getprovince()
                            );
                } else {
                    System.out.println("不存在该学生");
                }
                break;
            case 2:
                System.out.println("请输入身份证号");
                String studentid = scanner.next();
                int idint = findStudentByid(studentid);
                if (idint != -1) {
                    System.out.println("查找信息为:身份证号:"
                            + studentlist.get(idint ).getnumber() + "    姓名:"
                            + studentlist.get(idint ).getName() +"    性别:"
                            +studentlist.get(idint ).getsex()   +"    年龄:"
                            +studentlist.get(idint ).getyaer()+"   地址:"
                            +studentlist.get(idint ).getprovince()
                            );
                } else {
                    System.out.println("不存在该学生");
                }
                break;
            case 3:
                isTrue = false;
                System.out.println("程序已退出!");
                break;
            default:
                System.out.println("输入有误");
            }
        }
    }

    public static int findStudentByname(String name) {
        int flag = -1;
        int a[];
        for (int i = 0; i < studentlist.size(); i++) {
            if (studentlist.get(i).getName().equals(name)) {
                flag= i;
            }
        }
        return flag;
    }

    public static int findStudentByid(String id) {
        int flag = -1;

        for (int i = 0; i < studentlist.size(); i++) {
            if (studentlist.get(i).getnumber().equals(id)) {
                flag = i;
            }
        }
        return flag;
    }
}

Student:

package id1;

public class Student {

    private String name;
    private String number ;
    private String sex ;
    private String year;
    private String province;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getnumber() {
        return number;
    }
    public void setnumber(String number) {
        this.number = number;
    }
    public String getsex() {
        return sex ;
    }
    public void setsex(String sex ) {
        this.sex =sex ;
    }
    public String getyaer() {
        return year;
    }
    public void setyear(String year ) {
        this.year=year ;
    }
    public String getprovince() {
        return province;
    }
    public void setprovince(String province) {
        this.province=province ;
    }
}

实验结果如下所示:

本周学习总结:

通过将近一周的学习以及自己在后期的自学过程当中,我深入了解了什么叫做继承,以及在继承中所包含的类型有哪些。继承是用已有类来构建新类的一种机制,当定义了一个新类继承了一个类时,这个新类继承一个类时,这个新类就继承了这个类的方法和域。而且继承是具有层次的,其代码也是可重用的,可以轻松定义子类。首先在学习过程当中我们学习了类,超类和子类的定义,让我明白了父类和子类时相对的。还学习了泛型数组列表与对象包装器与自动装箱,在后面还介绍了反射的概念,它是在程序运行期间发现更多的类及其属性的能力。

原文地址:https://www.cnblogs.com/791683057mxd/p/9724641.html

时间: 2024-10-08 21:06:39

实验六 继承定义与使用的相关文章

201771010124 王海珍 《实验六 继承定义与使用》第六章实验总结

第一部分:理论知识学习部分 第五章 第五章学习内容主要分为七个模块,分别为: 1.类.超类和子类: a. 类继承的格式: class 新类名extends已有类名. b. 已有类称为:超类(superclass).基类(base class) 或父类(parent  class) 新类称作:子类(subclass).派生类(derived  class)或孩子类(child class) c.super是一个指示编译器调用超类方法的特有关键字,它不是一个对象的引用,不能将super赋给另一个对象

实验六 利用三层交换机实现VLAN间路由

实验六 利用三层交换机实现VLAN间路由 一.实验目标 掌握交换机Tag VLAN的配置 掌握三层交换机基本配置方法: 掌握三层交换机VLAN路由的配置方法: 通过三层交换机实现VLAN间相互通信: 二.实验背景 某企业有两个主要部门,技术部和销售部,分处于不同的办公室,为了安全和便于管理对两个部门的主机进行了VLAN的划分,技术部和销售部分处于不同的VLAN,先由于业务的需求需要销售部和技术部的主机能够相互访问,获得相应的资源,两个部门的交换机通过一台三层交换机进行了连接. 三.技术原理 三层

第八周总结和实验六

实验六 Java异常 实验目的 理解异常的基本概念: 掌握异常处理方法及熟悉常见异常的捕获方法. 实验要求 练习捕获异常.声明异常.抛出异常的方法.熟悉try和catch子句的使用. 掌握自定义异常类的方法. 实验内容 编写一个类,在其main()方法中创建一个一维数组,在try字句中访问数组元素,使其产生ArrayIndexOutOfBoundsException异常.在catch子句里捕获此异常对象,并且打印"数组越界"信息,加一个finally子句,打印一条信息以证明这里确实得到

实验6 继承

一.实验目的与要求: 复习运算符重载并应用. 了解并掌握通过继承派生出一个新的类的方法. 二.实验过程: 完成实验6继承中A-C三道题,见:http://acm.hpu.edu.cn/contest.php?cid=1018,密码:c++06.将答题过程简单记录到实验过程中. 将答题结果写到实验结果中,并根据答题结果进行分析.反思,将其写到实验分析中,并写上实验时间. 请按以上要求认真填写实验报告.

实验八——函数定义及调用总结

实验八--函数定义及调用总结 1.本次课学习到的知识点: (1)void为不反回结果的函数,且void不能省略,否则默认为int,函数体中没有表达式的return语句,也可省略return. (2)不返回结果的函数在定义.调用.参数传递.函数声明上,思路与以前相同,适用于把一些确定的.相对独立的程序功能封装成函数. (3)局部变量:定义在函数的内部,且有效作用范局部变量一般定义在函数或复合语句的开始处,围局限于所在的函数内部,形参是局部变量. (4)不能定义在中间位置. (5)全局变量:定义在函

软件测试实验六

请用所学的软件测试知识和技术方法,对bookstore项目中的购物车模块进行测试,并写出测试的缺陷报告. 说明: 1.bookstore项目即实验7发给大家的项目 2.要求至少发现2个缺陷,即要写2份缺陷报告 3.缺陷报告参考课本P264页 4.缺陷报告中的严重度和优先级按照课本P263页中规定的严重度和优先级 5.页面布局.美观.链接等不符合需求,也算缺陷,但本题请不要写这些方面的缺陷,否则不给分. 购物车模块缺陷报告 缺陷编号:01.01.01                        

CCNP实验六:修改OSPF特定邻居源的路由管理距离

一:基本配置 r1(config)#router ospf 1 r1(config-router)#net 1.1.0.0 0.0.255.255 area 1 r1(config-router)#net 12.1.1.1 0.0.0.0 area 0 r1(config-router)#redistribute connected subnets r2(config)#router ospf 1 r2(config-router)#net 12.1.1.2 0.0.0.0 area 0 r2(

【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验六:数码管模块

实验六:数码管模块 有关数码管的驱动,想必读者已经学烂了 ... 不过,作为学习的新仪式,再烂的东西也要温故知新,不然学习就会不健全.黑金开发板上的数码管资源,由始至终都没有改变过,笔者因此由身怀念.为了点亮多位数码管从而显示数字,一般都会采用动态扫描,然而有关动态扫描的信息请怒笔者不再重复.在此,同样也是动态扫描,但我们却用不同的思路去理解. 图6.1 6位数码管. 如图6.1所示,哪里有一排6位数码管,其中包好8位DIG信号还有6位SEL信号.DIG为digit,即俗称的数码管码,如果数码管

数据结构-实验六 排序

实验六   排序   l  实验目的 1.排序的基本概念 1.掌握在数组上进行各种排序的方法和算法. 2.深刻理解各种方法的特点,并能灵活应用. 3.加深对排序的理解,逐步培养解决实际问题的编程能力. l  实验内容 1.排序的基本概念 (一)基础题 1.编写各种排序方法的基本操作函数: (1)s_sort(int e[],int n)选择排序: (2)si_sort(int e[],int n)直接插入排序: (3)sb_sort(int e[],int n)冒泡排序: (4)merge(in