I am taking an intro to Computer Science and have been doing pretty well so far. Alot of the programming is getting tough as of late and my assignment is to do this:
Write a C++ program that prompts the user to enter an integer x at the keyboard. Your main function should store the user's integer x, then invoke two non-value returning functions as follows:
printVar(x); // Prints the value of x
changeVar(x); // Squares x (x times x), then adds 5 to x
printVar(x); // Prints the new value of x
The printVar function should pass the parameter by value.
The changeVar function should pass the parameter by reference.
Is there any way you guys coul help me this? I am a graphic Designer that needs to take this course as a pre=requisite for an html course which Im pumped up for.
Actually Computer Science provide the basic foundation for you to build on and that's why you need it. HTML, Android, ASP etc whatever are programming/markup scripting languages etc but they do not differ much from the Comp. Sci. fundamentals (algorithms and data structures appear in my mind)
Of cuz some schools/Unis take short-cut as they just want to churn out enough X-language trained graduates to fulfill workforce requirements.
I can understand it's kinda stressful for a newbie to learn call-by-value and call-by-reference, though
these two main function should be helpful..
you should try the rest part by yourself
1 2 3 4 5 6 7 8 9 10 11
void printVar(int x)
{
cout << "An integer X is:" << x <<endl;
}
void changeVar(int& x)
{
x = x * x;
x = x + 5 ;
}