|
COleDateTime::operator +, -
This might be useful.
Disclaimer: I've never used it but it appears to claim to do what your asking.
|
|
|
|
|
dear profesional over here...please help me with this problem,i have been trying to solve this problem for pass few hours..and i am still a beginner but the task given to me was too tough for me..
this program has 3 errors..i am halfway stuck please help me..
below is da task given to me..please help and do explain me my mistake.
i want to improve..
--Create several files of integers to be used to test sorting methods. Make files of several sizes, for example, size 20, 200, and 2000. Make files that are in order, in reverse order, in random order, and partially in order. By keeping all this test data in files (rather than generating it with random numbers each time the program is run), the same data can be used to test different sorting methods, and hence it will be easier to compare their performance.
--Write a menu-driven program for testing various sorting methods. One option is to read a file of integers into a list. Other options will be to run one of various sorting methods on the list, to print the unsorted or the sorted list, and to quit. After the list is sorted and (optionally) printed, it should be discarded so that testing a later testing method will start with the same input data. Write the program such that each new sorting method will process the original input file.
--Include code in the program to calculate and print
a. CPU time
b. The number of comparisons of keys.
c. The number of assignments of list entries during sorting a list.
Counting comparisons and assignments requires setting up global variables and inserting code into each sorting procedure to increment one of these global variables each time a key comparison and entry assignment is made.
#include <iostream><br />
#include<iomanip.h><br />
#include<math.h><br />
#include <ctime><br />
#include <cstdlib><br />
#include <math.h><br />
int com,call,move;<br />
#define MAX 10<br />
int array[1000];<br />
int arr[], n;<br />
<br />
<br />
<br />
void insertionsort(int array[], int size);<br />
int count1,count2;<br />
void merge(int array[],int first,int mid,int last);<br />
void mergesort(int array[],int first,int last);<br />
void random(int sizeofarray);<br />
void partial(int sizeofarray);<br />
void sorted(int sizeofarray);<br />
void inverse(int sizeofarray);<br />
void insertion();<br />
void random(int sizeofarray)<br />
{<br />
srand(time(NULL));<br />
for (int i = 1 ; i <= sizeofarray ; i++)<br />
{<br />
array[i]=rand();<br />
cout<<array[i]<<endl;<br />
<br />
}<br />
<br />
}<br />
<br />
void inverse(int sizeofarray)<br />
{<br />
for(int i = sizeofarray ; i >= 1 ; --i)<br />
{<br />
array[i]=i;<br />
cout<<array[i]<<endl;<br />
}<br />
}<br />
<br />
void sorted(int sizeofarray)<br />
{<br />
for (int i = 1 ; i <= sizeofarray ; i++)<br />
{<br />
array[i]=i;<br />
cout<<array[i]<<endl;<br />
}<br />
}<br />
<br />
void partial(int sizeofarray)<br />
{<br />
for (int i = 1 ; i <= sizeofarray-5 ; i++)<br />
{<br />
array[i]=i;<br />
cout<<array[i]<<endl;<br />
}<br />
for ( i = 10 ; i >= sizeofarray-5 ; i--)<br />
{<br />
array[i]=i;<br />
cout<<array[i]<<endl;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
void merge(int array[],int first,int mid,int last)<br />
{<br />
int temp[1000];<br />
int first1 = first;<br />
int last1 = mid;<br />
int first2 = mid + 1;<br />
int last2 = last;<br />
<br />
int index = first1;<br />
<br />
for (;(first1 <= last1) && (first2 <= last2); ++index)<br />
{<br />
if (array[first1] < array[first2])<br />
{<br />
temp[index] = array[first1];<br />
++first1;<br />
com++;<br />
}<br />
else<br />
{<br />
temp[index] = array[first2];<br />
++first2;<br />
com++;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
for (; first1 <= last1 ; ++first1 , ++index)<br />
{<br />
temp[index] = array[first1];<br />
move++;<br />
}<br />
for (; first2 <= last2 ; ++first2 , ++index)<br />
{<br />
temp[index] = array[first2];<br />
move++;<br />
}<br />
<br />
<br />
for( index = first ; index <= last ; ++index)<br />
{ <br />
array[index]=temp[index];<br />
move++;<br />
}<br />
<br />
}<br />
void mergesort(int array[],int first,int last)<br />
<br />
{<br />
if (first < last)<br />
{<br />
int mid= (first + last)/2;<br />
mergesort(array,first,mid);<br />
mergesort(array,mid+1,last);<br />
call++;<br />
merge(array,first,mid,last);<br />
}<br />
}<br />
<br />
void insertionSort()<br />
{<br />
arr[MAX],n;<br />
<br />
void getdata();<br />
void showdata();<br />
int sortLogic(int d[], int n2);<br />
};<br />
<br />
void sortLogic(int data[], int n)<br />
{<br />
for (int i=1, j; i<n; i++)<br />
{<br />
int tmp = data[i];<br />
for (j=i; j>0 && tmp<data[j-1]; j--)<br />
data[j] = data[j-1];<br />
data[j] = tmp;<br />
}<br />
<br />
}<br />
<br />
<br />
void getdata()<br />
{<br />
<br />
cout<<"How many elements you require: ";<br />
<br />
cout<<"Enter the elements of your array: ";<br />
cin>>n;<br />
for (int i=0; i<n; i++)<br />
cin>>arr[i];<br />
sortLogic(arr,n);<br />
}<br />
<br />
void showdata()<br />
{ <br />
cout<<"\n--Display--\n";<br />
for (int i=0; i<n; i++)<br />
cout<<arr[i]<<" ";<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
void main()<br />
<br />
{<br />
int i;<br />
int n=0;<br />
double number;<br />
int level;<br />
int sizeofarray;<br />
int operation;<br />
int function;<br />
int type;<br />
int choices;<br />
int choices1;<br />
int choices2;<br />
<br />
top:<br />
<br />
cout<<"Welcome to my program assignment 1"<<endl;<br />
cout<<""<<endl;<br />
cout<<"Please choose the type of sorting you would like to use:"<<endl;<br />
cout<<""<<endl;<br />
cin>>choices;<br />
<br />
switch(choices)<br />
{<br />
case 1:<br />
insertionSort();<br />
break;<br />
case 2:<br />
mergesort(array,0,n);<br />
break;<br />
<br />
default:<br />
cout<<"Please enter either one of the number only"<<endl<<endl;<br />
goto top;<br />
<br />
<br />
cout<<"Enter the number of array size you wish to create : ";<br />
cin>>sizeofarray;<br />
cout<<"Your array size now is "<<sizeofarray<<endl<<endl;<br />
cout<<"Now select which one fuction you want to sort !"<<endl;<br />
cout<<"1) for using Random Array."<<endl;<br />
cout<<"2) for using Partially Sorted Array."<<endl;<br />
cout<<"3) for using Sorted Array."<<endl;<br />
cout<<"4) for using Inversely Sorted Array."<<endl<<endl;<br />
cout<<"Your choice is ";<br />
cin>>function;<br />
cout<<endl;<br />
<br />
switch(function)<br />
{<br />
case 1:<br />
random(sizeofarray);<br />
break;<br />
case 2:<br />
partial(sizeofarray);<br />
break; <br />
case 3:<br />
sorted(sizeofarray);<br />
break;<br />
case 4:<br />
inverse(sizeofarray);<br />
break;<br />
<br />
default:<br />
cout<<"Please enter the any above number only!"<<endl<<endl;<br />
goto top;<br />
break;<br />
}<br />
<br />
int first=0;<br />
int last=sizeofarray-1;<br />
mergesort( array,first,last);<br />
cout<<endl<<"The above array is Unsorted Array :"<<endl;<br />
<br />
cout<<endl<<"The Sorted Array is show as below :"<<endl<<endl;<br />
for ( i=1 ; i <= sizeofarray ; i++)<br />
{<br />
cout<<array[i]<<endl; <br />
}<br />
<br />
for (n=0;n<20 && number<=sizeofarray ;n++)<br />
{<br />
number=pow(2,n);<br />
}<br />
level=n-2;<br />
operation=3*count1-1;<br />
cout<<endl<<"The total level is : "<<level<<endl;<br />
cout<<"The total number of comparisons is : "<<com<<endl;<br />
cout<<"The total number of move is : "<<move<<endl;<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
|
|
|
|
|
The same question was posted by another user a few posts ago.
Can you ask your teacher not to give out this forum's URL as a training assistant?
Homework questions are there to test knowledge you should already have been given in your class.
Iain.
|
|
|
|
|
not given any lecture about this...i am not asking to do the coding for me..atleast help me out with some solution...i m willing to do n learn my own...
|
|
|
|
|
makaveli_07 wrote: i am still a beginner but the task given to me was too tough for me..
So why not do the logical thing and start with a less ambitious project? Sorting data structures is not a beginner's project.
makaveli_07 wrote: below is da task given to me..
Yes, we know. Please tell your instructor that you are not ready for it just yet.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I recommend finding a copy of “Algorithms in C” by Robert Sedgewick, usually easier to understand than Knuth’s books, or just search the Web.
You have a lot to learn, passing the size of a global array makes no sense because it will lead to errors; if the array is global then the variable, or “#define” statement, telling you the size, should also be global.
Simplify: Start small by writing code that does not require external files, say a few arrays of integers. That way any good debugger will show you what is happening (single stepping). Then work your way up, one step at a time. Believe it or not, but that is how a lot of us solve these types of problems.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I need to change color of some STATIC control in MFC - how to do it ?
|
|
|
|
|
Derive a class from CStatic and handle OnCtlColor or OnPaint .
|
|
|
|
|
This one[^] works for me.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
You can also respond to the WM_CTLCOLORSTATIC message in the parent window
and set the control's color(s) ...
ON_MESSAGE(WM_CTLCOLORSTATIC, OnCtlColorStatic)
...
RedBrush.CreateSolidBrush(RGB(0xFF,0x00,0x00));
...
LRESULT CMMyDlg::OnCtlColorStatic( WPARAM wParam, LPARAM lParam)
{
HDC hDC = (HDC)wParam;
HWND hWnd = (HWND)lParam;
if (IDC_MYSTATIC == ::GetWindowLong(hWnd, GWL_ID))
{
::SetTextColor(hDC, RGB(0x00,0xFF,0xFF));
::SetBkColor(hDC, RGB(0xFF,0x00,0x00));
return (LPARAM)(HBRUSH)RedBrush;
}
return Default();
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have some ATL Composite control that i wrote - this Control "site" in some dialog.
I want to throw some event from this Control into the dialog - how can i do it ?
Thanks.
|
|
|
|
|
Yanshof wrote: I have some ATL Composite control that i wrote - this Control "site" in some dialog.
I want to throw some event from this Control into the dialog - how can i do it ?
Some platforms, including MFC and VB6 provide easy support for receiving control events in a dialog. If you aren't using one, or are using the control in a way that the platform doesn't support, you'll need to implement the control's event sink interface, and register it with the controls connection points when you create the control, and unregister it before destroying the control. You can look up info on IConnectionPointContainer and IConnectionPoint for more info on this.
Nathan
|
|
|
|
|
How do i create several files of integers to be used to test sorting methods. Make files of several sizes, for example, size 20, 200, and 2000. Make files that are in order, in reverse order, in random order, and partially in order.They should also have CPU time,the number of comparisons of keys and the number of assignments of list entries during sorting a list.
The code i have posted below,Thank you for ur help.
#include<iostream>
#include<iomanip>
using namespace std;
//function declarations
void selection_sort(int array[], int size);
void insertion_sort(int array[], int size);
int bin_search(int array[], int size, int item_sought);
void displayarray(int array[]);
void main()
{
//initialization of variables
int choice=0;
int sortarray[3]={0};
int item=0;
int i=0;
while (choice !=-1)
{
choice=0;//This is to make sure the loop executes again
while (choice != 1 && choice !=2 && choice !=3)
{
cout << "1 for selection sort, 2 for insertion sort, 3 for binary search" << endl;
cin >> choice;
}
cout << "Please enter 3 values in a row to use for the sort algorithm" << endl;
//input array values
for (i=0;i<3;i++)
cin >> sortarray[i];
//menu style selector for the user
if (choice==1)
selection_sort(sortarray, 3);
else if (choice==2)
insertion_sort(sortarray, 3);
else if (choice==3)
{
cout << "enter number sought";
cin >> item;
bin_search(sortarray, 3, item);
}
else
cout << "poor choice skippy" << endl;
cout << "Enter -1 to quit, make sure to enter a number, any number, otherwise" << endl;
cin >> choice;
}
}
void selection_sort(int array[], int size)
{
int n = size; // 0
for(int i = 0; i < n - 1; i++) // 1
{// 2
int smallest = array[i]; // 3
int small_pos = i; // 4
for(int j = i + 1; j <= n - 1; j++) // 5
if (array[j] < smallest) // 6
{ // 7
smallest = array[j]; // 8
small_pos = j; // 9
} // 10
array[small_pos] = array[i]; // 11
displayarray(array);
array[i] = smallest; // 12
displayarray(array);
} // 13
}
void insertion_sort(int array[], int size)
{
int next_element;
int n = size; // 0
for(int i = 1; i <= n - 1; i++) // 1
{ // 2
next_element = array[i]; // 3
int j = i; // 4
while(j > 0 && next_element < array[j-1])// 5
{
array[j] = array[j-1];
j--;
displayarray(array);
}
array[j] = next_element;
displayarray(array);
}
}
int bin_search(int array[], int size, int item_sought)
{
int n = size;
int first = 0;
int middle;
int last = n - 1;
bool found = false;
while(first <= last && !found)
{
middle = (first + last) / 2;
if(item_sought < array[middle])
last = middle - 1;
else if(item_sought > array[middle])
first = middle + 1;
else
found = true;
displayarray(array);
}
if(found)
return middle;
else
return n;
}
void displayarray(int array[])
{
//This function displays the values of the array
for (int i=0;i<3;i++)
cout << setw(2) << array[i];
cout << endl;
}
|
|
|
|
|
|
Is it possible to ignore users?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Nelek wrote: Is it possible to ignore users?
unfortunately, not that i know about.
|
|
|
|
|
This[^] is not the exact answer, but will help in your logic.
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
I'm still not sure with the example that was given..please explain to me
|
|
|
|
|
Why?
You are not reading what we tell you. And no one is going to make your homework. If you don't ask concrete things, you are not going to have answers (at least from me) anymore
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
i have a tip for you.
go back to school, and listen at the teacher when it explains
|
|
|
|
|
I have the following code:
RECT rect;
HWND h=GetDlgItem(IDC_PIC);
HDC tDC = ::GetDC(h); //Get the DC for the Picture Box
::GetClientRect(h,&rect);//Get dimensions of it
Here IDC_PIC is the id of the Picture Box control.
First Line of the code returning a valid pointer.
but ::GetDC(h) is initializing tdc with NULL value b'coz of which i am not able to do what i want.
One thing also rect is also giving garbage values.
I am using MFC.
Can any one tell me why?
Dhiraj
|
|
|
|
|
What do you want to do, exactly?
|
|
|
|
|
Dhiraj kumar Saini wrote: I am using MFC
Could have fooled me - I only see one call to an MFC class method,
and it shouldn't even compile.
What if you do this:
CWnd *pPictureCtlWnd = GetDlgItem(IDC_PIC);
if (pPictureCtlWnd)
{
CClientDC PictureCtlDC(pPictureCtlWnd);
CRect rect;
pPictureCtlWnd->GetClientRect(&rect);
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Dhiraj kumar Saini wrote: HWND h=GetDlgItem(IDC_PIC);
Are you using MFC or SDK.
In if it's MFC, then it should be like -
CWnd *pWnd = GetDlgItem (IDC_PICT);
CDC *pDC = pWnd->GetDC ();
pDC->TextOut (1,1,"hi",2);
else
If it's SDK, then the GetDlgItem also need the handle to parent.
HWND h=GetDlgItem(Handle to the dialog box that contains the control,IDC_PIC);
|
|
|
|
|
Is it possible to change scrollbars appearance on CListCtrl with OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult ) ?
Code sample?
Thanks in advance!
|
|
|
|
|