Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

if you have following 5 questions, how you will answer them. This is C++ and I\'

ID: 3812778 • Letter: I

Question

if you have following 5 questions, how you will answer them. This is C++ and I'm just asking you to write, in some cases, snippets of (syntactically correct) code. You do not need to write an entire program.

1.You will have to write a new method for some class we covered. Here, I just expect that you write the method; it doesn't have to be put in the context of class itself, so it's just like writing a single function. Namely, you'll specify a return type, a method name, a (possibly empty) parameter list, curly braces delimiting the body of the function and of course, the body of the function itself. For example,
void foo(int bar) {
// some valid C++ statements
}

2.You will have to write a sequence of C++ statements that realize some specified state or behavior. For example,
statement1;
statement2;
// etc.
// etc.

3.A grammar-related question, that among other things, will require writing a function analogous to the manner present above in 1.

4.Brings out the artist in you; you'll have to draw me some pictures.

5.You'll have to provide the declaration and definition of some method. For example:
// Declare a method requires simply writing a function prototype
void foo(int bar);
// Defining the method requires the use of scope resolution operator:
void SomeClass::foo(int bar) {
// some code
}

Explanation / Answer

1) Fnction defintion

/*

Name: display

Parameter list: None

Return : None

Fnction: displays the message "Hello world on to screen"

*/

void display()
{
   cout << "Hello world" << endl;
}

2.

//below is declartive statement, which declares two variables a, b which are of integer type

int a, b;

//below statement assigns value to integer type declared above

a = 10;

3. writing function which is analogous to Q1

int SumOfTwoNumbers(int a, int b)
{
   int sum;
   sum = a + b;
   return sum;
}

above function takes two integer arguments and return the sum of a and b.

4. Don't know what type of drawing they are asking.just drwaing UML diagram

I am drawing UML diagram of class dummy

Dummy

Name:int

Location:int

Set_a()

5. To define the method of the class we need to have class as below

class dummy

{

int a;

public:

dummy(){ };

void set_a(int value);

};

To define the method set_a of class dummy , we have to use scope resolution operator :: as below

void dummy::set_a(int value)

{

a = value;

}

above method is used to set the private variable 'a' of class dummy .

Dummy

Name:int

Location:int

Set_a()