Question

Find the syntax error(s) in the following class and function definition. [You need to identify the line number only). 1. clas

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Error 1:

Line Number: 3 => Missing : after private (private:)


Error 2:

Line Number: 5 => Missing : after public (public:)

Error 3:

Line Number: 6 => class1 is termed incorrectly... It should be Class1

Error 4:

Line Number: 6 => class1 constructor should not be preceded by class name

Error 5:

Line Number: 8 => Missing ; after class closing }

Error 6:

Line Number: 9 => class1 is termed incorrectly... It should be Class1

Error 7:

Line Number: 9 => Constructor Class1 should be preceded by class name Class1

Error 8:

Line Number: 9 => Missing Scope resolution operator (::)


Code after correcting all Syntax errors:


class Class1
{
   private:
       int data;
   public:
       Class1();
       double function1();
};

Class1::Class1()
{
   data=5;
}

Add a comment
Know the answer?
Add Answer to:
Find the syntax error(s) in the following class and function definition. [You need to identify the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • There are four syntax errors/incorrect statements in the following class definition. List the line numbers of...

    There are four syntax errors/incorrect statements in the following class definition. List the line numbers of the lines that contain errors, and then write the corrected line(s). (4 points) class jetType //Line 1 { //Line 2 public: //Line 3 void setValues(string, int, double); //Line 4 print() const; //Line 5 string getManufacturer() const; //Line 6 double getPrice() const; //Line 7 bool compareSeating(const jetType&); //Line 8 int jetType(); //Line 9 jetType(string); //Line 10 jetType(string, int, double); //Line 11 private; //Line 12 string...

  • // Please follow all the instructions Each of the class declarations and/or member function definitions below...

    // Please follow all the instructions Each of the class declarations and/or member function definitions below has syntax error(s). Find every error. All errors with explanation and fix the code. * Hint: You may use compiler to help you find the error. However, you need to set up the program correctly and to point out the true cause of the syntax error. Because the compiler messages are convoluted, due to the convoluted nature of language dependencies. 54. class Truck, public...

  • m The interface Measurable is defined as the following: /** An interface for methods that return...

    m The interface Measurable is defined as the following: /** An interface for methods that return the perimeter and area of an object. */ public interface Measurable { public double getPerimeter(); public double getArea(); } The class Rectangle implements the interface. The incomplete program is written as follows: 1 public class Rectangle 2 { private double width; private double height; public Rectangle(double w, double h) { width = w; height h; } { 3 4 5 6 7 8 9...

  • please solve 5 and 6 5. The following C function contains 6 syntax errors, identify them...

    please solve 5 and 6 5. The following C function contains 6 syntax errors, identify them and write the correct statements. double finalExam_Q1_5 ( ) { int x; i x2 for (i 1; i < 10; i++) if ! (O i <= 8) 2 3 4 = 10; 5)I (i-7 i if (i xx+i if (i-4) 4; 10 X - 11 12 return (x); 13 6. Declare a string str that can store up to 300 characters. Initialise it with...

  • The following individual two programs are using while loop in order to print a specific output:...

    The following individual two programs are using while loop in order to print a specific output: The outputs of the first program are: 10 9 8 5 4 The outputs of the second program are: 123456789 Using the Table 3.1 below, allocate the error(s) of each line of two programs and type of error: The first program: public Main { public static void main(String args[]){ int i=10 while(i>4){ System.out.print(i); i++; } } } The second program:   public class Main   {...

  • The following individual two programs are using while loop in order to print a specific output:...

    The following individual two programs are using while loop in order to print a specific output: The outputs of the first program are: 10 9 8 5 4 The outputs of the second program are: 123456789 Using the Table 3.1 below, allocate the error(s) of each line of two programs and type of error: The first program: public Main { public static void main(String args[]){ int i=10 while(i>4){ System.out.print(i); i++; } } } The second program:   public class Main   {...

  • QUESTION 18 According to class materials, the program is allowed to overload operators only if at...

    QUESTION 18 According to class materials, the program is allowed to overload operators only if at least one incoming parameter received by the operator has a class type. 1. (a) True 2. (b) False QUESTION 19 According to the course materials, a function can take value parameters and reference parameters. A value parameter is a separate variable from the one in main() or another calling function only if the function value parameter has a different name than the one in...

  • Question 6: Identify errors and correct them of the following Java program: 1.           import java.swing.*; 2.          ...

    Question 6: Identify errors and correct them of the following Java program: 1.           import java.swing.*; 2.           import java.awt.; 3.           public class ToppingPanel extends Panel 4.           { 5.           public final double CREAM_CHEESE = 0.50; 6.           public final double BUTTER = 0.25; 7.           public final double PEACH_JELLY = 0.75; 8.           public final double BLUEBERRY_JAM = 0.75; 9.           private JCheckBox creamCheese; 10.     private JCheckBox butter;      11.     private JCheckBox peachJelly; 12.     private JCheckBox blueberryJam; 13.       public ToppingPanel() 14.       { 15.       setLayout new GridLayout(4, 1));...

  • Given this code defining a class (shown with line numbers): 1: class newClass { 2: private:...

    Given this code defining a class (shown with line numbers): 1: class newClass { 2: private: 3: int a; 4: public: 5: void setA(int value) { a = value; } 6: int getA() { return a; } 7: newClass(int value) : a(value) {}; 8: newClass() { a = 0; } 9: }; Which of the following snippets of code, when written in main() where the class above has been defined, will cause a syntax error when compiled? newClass something; something.setA(8);...

  • C++ Consider the definition of the following class: (1,2,3, 5,7 clasa productTyp publie productType O productType(int....

    C++ Consider the definition of the following class: (1,2,3, 5,7 clasa productTyp publie productType O productType(int. double, double) productType (atring, int, double, double)s //tine6 productType (atring. atring.atring //Line1 /Line 2 /Line 3 //Line /Line s int, double, double) //Line 7 void set (atring, atring, string. int void print) const double, double) i //Line //tine 9 void setQuantitiesInstock (int x) void updateQuantitiesinstock (int x) int getQuantitiesInstock) const //Line 10 //Line 11 //Line 12 void #etPrice (double x); double getPrice) consti //Line...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT