Вы находитесь на странице: 1из 2

SALEM UNIVERSITY CSC 311 TEST SOLUTIONS

PART A 1. (a) False (b) True (c) False Java compiler is javac.exe while the interpreter is java.exe 2. (a) NO (b) NO (c) YES PART B 3. (a) A method of implementation in which programs are organized as cooperative collections of object, each of which represents an instance of some class, which have classes that are all member of a hierarchy of classes united by inheritance relationships. In such programs, classes are generally viewed as static, whereas objects typically have a much more dynamic nature, which is encouraged by the existence of polymorphism. (b) Encapsulation, polymorphism, and inheritance (See lecture note for details). (i) Encapsulation is a programming mechanism that binds together code and the data it manipulates, and that keeps both safe from outside interference and misuse. (ii) Polymorphism (from the Greek, meaning many forms) is the quality that allows one interface to access a general class of actions. The specific action is determined by the exact nature of the situation. (iii) Inheritance is the process by which one object can acquire the properties of another object. This is important because it supports the concept of hierarchical classification. (c) While it would be possible for a C++ compiler to generate bytecode rather than executable code, C++ has features that discourage its use for the creation of applets - the most important feature being C++s support for pointers. A pointer is the address of some object stored in memory. Using a pointer, it would be possible to access resources outside the program itself, resulting in a security breach. Java does not support pointers, thus eliminating this problem. 4. (a) An abstract method is a method without a body. (b) A package is a container for classes. It performs both an organization and an encapsulation role. (c) A stream is an abstraction that either produces or consumes information.

PART C
5. (a) /** To change this template, choose Tools | Templates * and open the template in the editor. */ package population_java; /** * @author Vincent */ public class Population_java { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here double population, Growth_Rate, Death_Rate, Birth_Rate; Growth_Rate = 10;

Death_Rate = 3; Birth_Rate = 6; population = (Growth_Rate * Math.sqrt(Death_Rate))/ Birth_Rate; System.out.println("Growth Rate = " +Growth_Rate); System.out.println("Death Rate = " +Death_Rate); System.out.println("Birth Rate = " +Birth_Rate); System.out.println("Population = " +population); } } (b) // soln_5b.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "math.h" int main() { double x, y, z, w; x = 1; y = 1; z = (2*x + 5*y); w = pow(z,7); printf("%.1f, %.1f, %.1f, %.1f\n", x, y, z, w); return 0; }

6. (a) // Hyper_Level_C.cpp application. // #include "stdafx.h" #include "math.h" #include "stdlib.h" #include "stdio.h"

Defines

the

entry

point

for

the

console

int main() { float Hyper_Level, Blood_Flow_Rate, Blood_Sugar; float Blood_Sugar_SQRT; Blood_Flow_Rate = 5; Blood_Sugar = 200; Blood_Sugar_SQRT = sqrt(Blood_Sugar); Hyper_Level = Blood_Flow_Rate * Blood_Sugar_SQRT; printf("\n"); printf("Blood Flow Rate = %.4f\n\n",Blood_Flow_Rate); printf("Blood Sugar Level = %.4f\n\n",Blood_Sugar); printf("Hypertension Level = %.4f\n",Hyper_Level); return 0; } (b) clear all clc x = 2; for n = 1:30 y(n) = x^n; end

Вам также может понравиться