Question

In: Computer Science

This is for C++ A static main() function defined in your homework assignments means: 1.The function...

This is for C++
A static main() function defined in your homework assignments means:

1.The function is always invisible to all functions outside of the class.

2.The function cannot declare any variables.

3.The function can be called without an instance.

4.The function can access all variables and methods.

5.The function can be called by the superclass.

Solutions

Expert Solution

Ans would be 3.The function can be called without an instance.

Option 1. Is incorrect because Static function() is not invisible to all the function outside the class, infact it can be accesed anywhere in the program scope using scope resolution operator with the class name.

Option 2 Is incorrect because a static function can declare its own variable, but cannot access non static variable of its own class.

Option 4. Is incorrect because a static function can only access static variable of its class.

Option 5. Is incorrect because a superclass object can not call a static function direclty as it is not defined/declared in the superclass scope, although vice versa is true and static method of super class can be called from derived class.

Explanantion:

By declaring a function member as static, you make it independent of any particular object of the class. A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.

A static member function can only access static data member, other static member functions and any other functions from outside the class.Static member functions have a class scope and they do not have access to the this pointer of the class. You could use a static member function to determine whether some objects of the class have been created or not.


Related Solutions

1. Genichi Taguchi defined the taguchi loss Function: Explain what the Taguchi Loss Function means for...
1. Genichi Taguchi defined the taguchi loss Function: Explain what the Taguchi Loss Function means for both the consumer and Manufacturer 2. Boothroyd Dewhurst Manual Assembly: What do alpha a beta define? 3. Draw a FAST diagram for a manual toothbrush. 4. Assuming you have your favorite coffee beans ground and you have a coffee type drip coffee maker. List the steps and draw a Process Flow Diagram for brewing a pot of coffee.
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
CODE: C# using System; public static class Lab6 { public static void Main() { // declare...
CODE: C# using System; public static class Lab6 { public static void Main() { // declare variables int hrsWrked; double ratePay, taxRate, grossPay, netPay=0; string lastName; // enter the employee's last name Console.Write("Enter the last name of the employee => "); lastName = Console.ReadLine(); // enter (and validate) the number of hours worked (positive number) do { Console.Write("Enter the number of hours worked (> 0) => "); hrsWrked = Convert.ToInt32(Console.ReadLine()); } while (hrsWrked < 0); // enter (and validate) the...
Being a college student means that you need to add time for assignments into your already...
Being a college student means that you need to add time for assignments into your already busy week. How do you plan on doing this? Where will school fit into your life l? What will you do differently? Let's talk about it, share our plans, and suggest ideas to help each other.
Utility function over clothing (C) and greens (G) is defined by the function U(C,G)=C^(1/4)+G^(1/4). Let P(of...
Utility function over clothing (C) and greens (G) is defined by the function U(C,G)=C^(1/4)+G^(1/4). Let P(of C) and P(of G) denote the prices of cherries and grapes respectively. W is income that is available to consumer to spend on those two goods. (a) Write down the customer's utility maximization problem. (b) set up the langrangian and solve for the first order condition. (c) Solve for the consumer's demand functions for clothing and greens. Please Explain.
Write a C++ program that inputs two simplified poker hands (as defined in homework #5) and...
Write a C++ program that inputs two simplified poker hands (as defined in homework #5) and determines which (if either) of the hands is the winner, according to the following rules: • If the two hands have different types (3-of-kind, straight, pair, high-card), the hand with the better type (i.e., appears earlier in this list) wins. • If they have the same type, the higher significant card wins. • If the hands have the same type and significant card, there...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is allowed. The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to...
C++ Recursive Functions: Please call functions in a main function as well. 1. A recursive function...
C++ Recursive Functions: Please call functions in a main function as well. 1. A recursive function that print the reverse of a string. (e.g., void printReverse(string exp)). For example, if exp =”coding”, then the function should print out “gnidoc”. 2. Implement a non-recursion-based binary search function. Convert this function into a recursion-based function. 3. Implement a recursive and non-recursive Fibonacci function.
Write a C++ program which consists of several functions besides the main() function. The main() function,...
Write a C++ program which consists of several functions besides the main() function. The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. A value-returning function called Power(int a, int b) that...
In C Write a main function with a function call to a function called GetLetter which...
In C Write a main function with a function call to a function called GetLetter which has two double arguments/parameters. The function returns a character. Declare and initialize the necessary data variables and assign values needed to make it executable and to prevent a loss of information
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT