Please revise the program and correct the errors of the program and make varaibles a and b not accessible by ".".
For example, obj_X.a=0 should be wrong and it should be replaced by obj_X.setA(0);
Note: keep the meanings of the main function.
The output should be:
-------------------
Here are a and b: 0 1
---------------------
Submit the correct code and the running result.
#include <iostream>
using namespace std;
struct X {
int a;
int b;
public:
int getA() { return b; }
int getB() { return b; }
void setA(int x) { a=y; }
void setB(int y) { b=x; }
};
int main() {
X obj_X;
obj_X.a = 0;
obj_X.b = 1;
cout << "Here are a and b: " << obj_X.a << " " << obj_X.b << endl;
}
Step by stepSolved in 3 steps with 1 images
- When passing a variable to a function how should the variable be passed? a. Variables can't be passed to functions b. Either ByVal or ByRef (it doesn't matter) c. ByVal d. ByRefarrow_forward//Write a function that loops through and console.log's the numbers from 1 to 100, except multiples of three, log (without quotes) "VERY GOOD" instead of the number, for the multiples of five, log (without quotes) "SUPER AWESOME". For numbers which are multiples of both three and five, log (without quotes) "VERY GOOD SUPER AWESOME" Console log out: 12VERY GOOD4SUPER AWESOMEVERY GOOD78VERY GOODSUPER AWESOME11VERY GOOD1314VERY GOOD SUPER AWESOME1617VERY GOOD19SUPER AWESOMEVERY GOOD2223VERY GOODSUPER AWESOME26VERY GOOD2829VERY GOOD SUPER AWESOMEarrow_forwardI need the code in R. Thanksarrow_forward
- Hr, Min, Sec Constructors to handle: default, (4, 15, 6), (1,30), (14), (clock1) Overload <> ++,, >=, ==, != Get and Set methods. Write a tester program that creates 2 clocks(Input from the user). The first clock will represent the real time and one will represent your alarm clock. Do a loop that will continue to add 1 second to the current time and stop when it reaches the alarm clock time. Display the time each second on the screen. You can use system("CLS"); to clear the screen each time so it looks like it is overwriting the current time. #include void main() { system("cls"); }arrow_forwardPlease tell me where I get wrong.arrow_forwardThe Function will be able to calculate the area of the following polygons: Right triangles, Rectangles, and regular polygons. It will do so by taking the following inputs: - numSides – a double of the number of sides the polygon has - sideLengths – a double of the length or lengths of sides of the polygon The program should determine if the inputs are formatted properly. The rules are: - numSides must be a positive integer number with values greater than or equal to 3. - When numSides is 3 or 4, sideLengths can either be a scalar or an array with two values. - When numSides is greater than 4, sideLengths must be a scalar. To determine if a number is an integer, you can use the rem function. rem returns the remainder of whole number division. It has the following syntax: remainder = rem(numerator, denominator); Where remainder is the remainder of numerator/denominator. To use this to find whether a number is an integer, use rem in the following way: remainder = rem(number, 1); When…arrow_forward
- 4.Rohan bought a gallon of milk with an original price of $4.25; today he gets a 15% discount before a 5% tax; display the final price of the milk.5.This function is named compound_interest, takes these arguments p r n t; compute and return a for displaya = p (1 + r/n) nt6.This function is named annuities, takes these arguments r i n; compute and return s for displays = r ((1 + i)^(n + 1))/i - rarrow_forwardPython (this is not graded this is practice work that is not graded) write and test a function which takes two dates (month, day) list arguments.When the function is called with the two arguments, it returns the number of days betweenthose two dates. Print the returned value. It is assumed that the first date occurs first. Forinstance, if the users calls the function with FUNCTION([12, 10], [12, 20]) as arguments, thereturned value is 10 days. However, if FUNCTION([12, 20], [12, 10]) is called, the returnedvalue is -10 days.Assume February has 28 days.Test data: [10, 30], [5, 20] [1, 30], [5, 25] [5, 25], [1, 30] [1, 1], [12, 31]arrow_forwardThe input alphabet for a Finite State Recogniser consists of a '#', the lower-case letters a - z and the digits 0-9. A valid input stream starts with a '#' and ends with a '#'. Between the #'s, there will be one or more digits and/or letters in any combination. Which of the strings below would not be accepted (or recognised) by the machine? #77# #789abd23# #23#xyz# #defg#arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education