I am using Microsoft Visual Studio 2010 and the C++ language. Below are the thre
ID: 3535486 • Letter: I
Question
I am using Microsoft Visual Studio 2010 and the C++ language. Below are the three questions.
1. Write a procedure void sort2(int& a, int& b) that swaps the values of a and b if a is greater than b and otherwise leaves a and b unchanged. For example:
Int u = 2;
Int v = 3;
Int w = 4;
Int x = 1;
Sort2(u, v); // u is still 2, v is still 3
Sort2(w, x); // w is now 1, x is now 4
2. Write a function
double get_double(string prompt)
that displays the prompt string, followed by a space, reads the floating point number in, and returns it. (In other words, write a console version of cwin.get_double.)
here is a typical usage:
salary = get_double(“please enter your salary:â€) ;
perc_raise =
get_double(“what percentage raise would you like?â€);
if there is an input error, abort the program by calling exit(1).
3. Consider the following buggy program:
Employee read_employee()
{
Cout << “please enter the name: â€;
String name;
Getline(cin, name);
Cout << “please enter the salary: “;
Double salary;
Cin << salary;
Employee r(name, salary);
Return r;
}
When you call this function once, it works fine. When you call it again in the same program, it won’t return the second employee record correctly. Write a test harness that verifies the problem. Then step through the function. Inspect the contents of the string name and the employee object r after the second call. What values do you get?
Explanation / Answer
http://ideone.com/Vahazx
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.