Assume the false value is random assign in the array. The program will check by itself which index has a 'false' then print out the index number.
index 0 and 3 have 'false', then
print out "Q1 and Q4 is wrong"
I need help
Create a class Employee that includes:
1. Three instance variables: a Name(type string), HireYear(type
integer), and a monthly Salary (type double) .
2. A constructor that initializes the three instance variables .
3. Public methods :
a. Set and Get for each instance variable. If the monthly salary
is not positive, do not set its value .
b. GetEmployeeInfo: returns a string contains the employee
name, hire year, and his/her monthly salary.
in c++ : (Account Class) Create an Account class that a bank might use to represent customers' bank accounts. Include a data member of type int to represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data members. The constructor should validate the initial balance to ensure that it's greater than or equal to 0. If not, set the balance to 0 and display an error message indicating that the initial balance was invalid. Provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the function should print a message indicating "Debit amount exceeded account balance." Member function getBalance should return the current balance. Create a program that creates at least two Account objects and tests the member functions of class Account.
task 1:derived two classes from Account class
one is bank albilad data members visa, points o
ther is alrajhi bank data members mastercard, points
set and get functions and chargevisa and chargemastercards.
set not exceed account balance.
charge not exceed visa or mastercards balance.
set points visa 10%, mastercards 15%. get functions
Make appropriate member functions const.
task 2:disinherite the classes
C2893 (5) Failed to specialize function template
\include\algorithm Lines 7361, 7419, 7423, 7434, 7447
C2672 (5) 'operator __surrogate_func': no matching overloaded function found
\include\xutility Line 1622
C2780 (1) 'void std::sort(const _RanIt,const _RanIt)': expects 2 arguments - 3 provided
C2672 (1) 'sort': no matching overloaded function found
C3867 (1) 'RDA_Names::compare': non-standard syntax; use '&' to create a pointer to member
C2064 (5) term does not evaluate to a function taking 2 arguments
\include\xutility Line 1622
\include\algorithm Lines 7419, 7423, 7434, 7447
Although it's a waste of time to say this,
And I know you've heard it before.
But your answers were most pointed
And it clearly went to the fore.
We thank you all
My wife because I don't grumble
I with nothing to grumble about.
I have tried to follow all of your suggestions (my following is full). I now have pointers or references everywhere and the thing seems to compile without complaint. Now to get rid of those damn'd nuisance run-time errors.
where the comparison function is an anonymous lambda.
The next step is to look at how efficient your code will be. If you are sorting only 500 objects and you don't do it too often, it's probably OK. In general however your solution is highly inefficient. Every time sort has to exchange two elements it makes copies of the asset_Name string.
There are various ways to improve it:
- keep a unique_ptr pointer to string and provide a move constructor for the Asset structure.
- create an array of indexes in RDA_Names and sort it inseted of sorting the asset_Data array.
Your first point is right on, and gets me back to Case 2. You're second point is incorrect. What is being sorted is an object of some type. The sort routine ignores the type and whether the object containing the type is private or public. It only works on comparison, I assume signed char comparison if there is no comparison function, and the ability to index and swap. The comparison function has no cognizance of privacy, it is only passed pointers/objects and returns a bool.
At the sort base level, the input object need not be public, and if the input object contains objects, these contained objects need not be public.
Pretty much all you said is valid for the old C qsort function. std::sort is an entirely different beast. I suggest you carefully read the description at std::sort - cppreference.com[^]
The sort routine ignores the type and whether the object containing the type is private or public.
I'm not sure I understand what you mean by "the object containing the type". In C++ objects don't contain types. Besides the sort routine is not ignoring the object type at all. According to C++ reference: "The type of dereferenced RandomIt must meet the requirements of MoveAssignable and MoveConstructible". That requires at least a copy constructor for the object (either user defined or generated by the compiler).
The comparison function has no cognizance of privacy, it is only passed pointers/objects and returns a bool.
Of course not, the comparison function needs to access the members of the object in order to compare them. Either it is a member function or a friend function or the members in question are public.
The example on the C++ reference page mentioned above shows all the different methods you can use to invoke the std::sort algorithm.
Non-virtual functions don't change a class instance size. You can use this technique, as in existing Microsoft classes like CPoint, CRect, adding instance non-virtual functions and static functions, if necessary.
I am displaying an image in a static control (in a dialog) and trying to stretch according to the zoom factor on mouse position. Zoom on mouse position is working fine, but the image is not fitting inside the static control, going all over the dialog.
Below is the code.
// source image
Gdiplus::Bitmap *gpBitmap = new Gdiplus::Bitmap(mImagePath);
int origW = gpBitmap->GetWidth(); // 5298 - original width
int origH = gpBitmap->GetHeight(); // 2728 - original height
// destination rectangle
GetClientRect(hWnd, &rcVPC); // 501 X 255 - size of the static control
HDC hDc = GetDC(hWnd);
float perW = (float)rcVPC.right / (float)origW;
float perH = (float)rcVPC.bottom / (float)origH;
int newW = origW * perW * mVPZoomFactor; // starting factor is 1.0 and multiplying with 1.2 with each zoom
int newH = origH * perH * mVPZoomFactor;
Gdiplus::Bitmap *bmpResized = new Gdiplus::Bitmap(newW, newH, gpBitmap->GetPixelFormat());
Gdiplus::Graphics *graphics = new Gdiplus::Graphics(bmpResized);
graphics->DrawImage(gpBitmap, 0, 0, newW, newH);
int zoomWidth = (int)(0.5 + newW * mVPZoomFactor);
int zoomHeight = (int)(0.5 + newH * mVPZoomFactor);
//Find the position "factor"
double dXFactor = (double)rcVPC.right / stX; // stX, stY - mouse position on zoom
double dYFactor = (double)rcVPC.bottom / stY;
//Find the origin
int left = stX - zoomWidth / dXFactor;
int right = stY - zoomHeight / dYFactor;
HBRUSH hB = GetSysColorBrush(COLOR_3DDKSHADOW);
FillRect(hDc, &rcVPC, hB);
HDC hdcMem = CreateCompatibleDC(hDc);
HBITMAP oldBmp = (HBITMAP)SelectObject(hdcMem, hBmpVPCanvas);
StretchBlt(hDc, left, right, zoomWidth, zoomHeight, hdcMem, 0, 0, newW, newH, SRCCOPY);