ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 20 May 2017 My Price 9.00

Department of Computer Science CSc 4330/6330

Georgia State University

Department of Computer Science

 

CSc 4330/6330                                                                                                               K. N. King

Fall, 2016

 

Assignment 1

 

due September 14, 2016

 

 

All answers must be computer-printed, except for diagrams. Use your own words; do not copy material verbatim from a web site or other source.

 

1. On pages 24-25, Sebesta says that "the lexical units of a program are identifiers, special words, operators, and punctuation symbols." However, he overlooked one other significant category of lexemes. Name this category and give several examples.

 

2. How many lexemes does the following Java code contain?

 

1.  public class FtoC {

2.    public static void main(String[] args) {

3.      double fahrenheit = 98.6;

4.      double celsius = (fahrenheit - 32.0) * (5.0 / 9.0);

5.      System.out.print("Celsius equivalent: ");

6.      System.out.println(celsius);

7.    }

8.  }

 

Show the number of lexemes on each line (using the line numbers shown) as well as the total number of lexemes.

 

3. Compile the following Java program:

 

public class Demo {

  public static void main(String[] args) {

    int sum = 0;

    for (int i = 1; i <= 10; i++)

      sum += i;

  }

}

 

Then use javap with the -c option to disassemble the resulting class file. Turn in a listing of the disassembled file along with a brief description of what each line means. You can find an HTML version of the Java Virtual Machine Specification on the web, which should be helpful for answering this question.

 

4. Draw a diagram showing the internal representation of the following LISP list:

 

(((A) (B C) D) E)

 

Your diagram should resemble the figure on page 48 of Sebesta.

 

5. Fortran's assigned Goto statement was classified as "obsolescent" in the Fortran 90 standard.

 

(a) Was this statement removed from Fortran in Fortran 95? If not, was it removed in Fortran 2003?

(b) Describe the syntax of this statement.

(c) Describe the semantics of this statement.

(d) Explain why this statement is now considered to be a poorly designed language feature.

 

6. Suppose that the equal_lists function (page 49 of Sebesta) is called with the lists (A (B) (C D E)) and (A (B) (C D E)) as the arguments. How many calls of equal_lists will be performed altogether, including the original call and all recursive calls?

 

7. The following program is written in Dart, the new programming language from Google:

 

import 'dart:math' as math;

 

class Point {

  num x, y;

  Point(this.x, this.y);

  Point scale(factor) => new Point(x * factor, y * factor);

  num distance() => math.sqrt(x * x + y * y);

}

 

void main() {

  var p = new Point(2, 3).scale(10);

  print(p.distance());

}

 

(a) Explain the meaning of the word num.

(b) Translate the program into Java, making as few changes as possible. Use int as the type of x, y, and factor; use double as the return type of distance. Your answer should be a complete Java program that produces the same output as the original Dart program.

 

8. The following class contains several errors that violate the rules of Java:

 

 1.   public class Fraction {

 2.     private int numerator;

 3.     private int denominator;

 

 4.     public Fraction(int num, int denom) {

 5.       numerator = num;

 6.       denominator = denom;

 7.       reduce();

 8.     }

 

 9.     public Fraction(int num) {

10.       this(num, 1);

11.     }

 

12.     public Fraction() {

13.       this(0);

14.     }

 

15.     public int getdenominator() {

16.       return denominator;

17.     }

 

18.     pulbic int getNumerator() {

19.       return numerator;

20.     }

 

21.     public double toDoulbe() {

22.       return (double) numerator / (double) denominator;

23.     }

 

24.     public float toFloat() {

25.       return (float) numerator / denominator;

26.     }

 

27.     public string toString() {

28.       if (denominator == 1)

29.         return numerator + '";

30.       else

31.         return numerator + '/' + denominator;

32.     }

 

33.     void reduce() {

34.       int g = gdc(numerator, denominator);

 

35.       if (g != 0) {

36.         numerator /= g;

37.         denominator /= g;

38.       }

 

39.       if (denominator < 0) {

40.         numerator = -numerator;

41.         denominator =- denominator;

42.       }

43.     }

 

44.     private static int gcd(int m, int n) {

45.       while (n != 0)

46.         r = m % n;

47.         m = n;

48.         n = r;

49.       }

50.       return m;

51.     }

52.   }

 

Describe each error and specify whether it is (a) lexical, (b) syntactic, or (c) semantic. Use the numbers shown to identify the line on which each error occurs. The class may also contain programming errors that do not violate the rules of Java and will not be detected by a Java compiler. You should ignore these errors.

Answers

(11)
Status NEW Posted 20 May 2017 09:05 AM My Price 9.00

-----------

Attachments

file 1495272986-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)