|
snoop82 wrote: the algorithm tat i would like to insert
To where? Can't you just paste the code into your IDE in much the same way as you did here?
snoop82 wrote: I need help of how to implement it in here
It's already implemented. Are you wanting to call it?
"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
|
|
|
|
|
the algorithm tat i would like to insert
void selectionSort(int a[], int size)
{
int i, j, min;
for (i = 0; i < size - 1; i++)
{
min = i;
for (j = i+1; j < size; j++)
{
if (a[j] < a[min])
{
min = j;
}
}
swap(a[i], a[min]);
}
}
I need help of how to implement it in here
#include
using namespace std;
#include
#include
#include
#include
#include
typedef int dataType;
int innum[2000];
int size;
int number=0;
int num;
int i;
float b;
int assignment=0;
int compare=0;
int starttime, stoptime, timeused;
struct list
{
int info;
list*link;
};
list *first = NULL;
list *last = NULL;
list *newNode;
list *lhead = NULL;
list *lastnum; //last number
list *firstnum; //first number
list *current;
list *trailCurrent;
void linked()
{
list * newNode = new list;
newNode->info=num;
newNode->link=NULL;
if (first==NULL)
{
first=newNode;
last=newNode;
lhead=newNode;
}
else
{
last->link= newNode;
last= newNode;
}
}
void sort()
{
int tmp, index;
for (int firstnumber=1; firstnumber
if (innum[firstnumber]
{
tmp= innum[firstnumber];
index= firstnumber;
do
{
innum[index]=innum[index-1];
index--;
}
while (index>0 && innum[index-1]>tmp);
innum[index]=tmp;
assignment++;
}
cout<<"\nBelow Are The Sorted Numbers"<<"\n\n";
for(int j=0; j
{
cout<<innum[j]<<"\t";
}
stoptime =="" clock();
timeused="stoptime" -="" starttime;
cout="" <<="" "\ncpu="" time:="" "="" timeused="" 1000="" ms."="" endl;
="" system("pause");
}
int="" main()
{
float="" a;
cout<<"\n*********************";
cout<<"\n*="" 1.="" random="" 20="" *";
cout<<"\n*="" 2.="" 200="" 3.="" 2000="" *";
cout<<"\n*********************";
cout<<"\n*="" 4.="" in="" order="" 5.="" 6.="" 7.="" reverse="" 8.="" 9.="" *";
cout<<"\n*********************";
cout<<"\nplease="" choose="" as="" above:="" ";
cin="">>a;
if (a==1)
{
size=20;
ifstream input ("random20.txt", ios::in);
cout<<"\nBelow Are The Unsorted Numbers\n\n";
for ( i=0; i<20; i++)
{
input>>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=2)
{
size=200;
ifstream" input="" ("random200.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<200;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
} sort();
cout<<"\nnumber="" of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=3)
{
size=2000;
ifstream" input="" ("random2000.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<2000;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=4)
{
size=20;
ifstream" input="" ("order20.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<20;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=5)
{
size=200;
ifstream" input="" ("order200.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<200;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=6)
{
size=2000;
ifstream" input="" ("order2000.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<2000;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=7)
{
size=20;
ifstream" input="" ("reverse20.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<20;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=8)
{
size=200;
ifstream" input="" ("reverse200.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<200;="" i++)
{
input="">>num;
innum[i]=num;
cout<<num<<"\t";
}
sort();
cout<<"\nnumber of="" comparisons:\t"<<compare<<"\n";
cout<<"\nnumber="" assignment:\t"<<assignment<<"\n\n";
}
if="" (a="=9)
{
size=2000;
ifstream" input="" ("reverse2000.txt",="" ios::in);
cout<<"\nunsorted="" numbers\n\n";
for="" (int="" i="0;" i<2000;="" i++)
{
input="">>num;
innum[i]=num;
cout<
|
|
|
|
|
Why did you paste your ENTIRE program again? Once is MORE THAN enough.
"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 am sorry..well i didnt mean that..well the coding which i've pasted earlier... i would need to implement another sorting method as well.Im choosing selection sort.But i don't know to include it into the coding ...so i would need to be having a menu such as choose either insertion or selection ...and then it would go into the float a..please do guide me.Well it should also do the sorting,comparison and also the time.Thank you.
|
|
|
|
|
For pete's sake, man, ditch this program and start with something way more simple. I suggest purchasing a book or at least borrowing one from your local library.
No offense personally, but to carry on with your current endeavor is a waste of your time and ours. Learning how to code up a useful program, while fun, is completely comprehensive in that one step builds upon the previous one. Skipping the small stuff is just a recipe for failure.
"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
|
|
|
|
|
Sorry, I didn't see it, can you post it once again ?
I mean, you posted it three times, why not a fourth time, in case somebody missed it ?
|
|
|
|
|
snoop82 wrote: whereby it would perform the same actions as the coding.I don't know to make a menu driven of choosing the sorting also.
Let me get this straight. YOu've written a sorting algorithm, something pretty complex, by you can't write something that puts up a menu and accepts a little keyboard input, something VERY simple???
Tell me why I seriously doubt you wrote the sorting algorithm... Sounds more like copy'n'pasted one to me.
|
|
|
|
|
well i've got it from the net and tried doing it and i'm a beginner ..and i'm like losing hope..please help me
|
|
|
|
|
snoop82 wrote: ..and i'm like losing hope..
Coincidentally, so are we
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Please do help me...pls do guide me
|
|
|
|
|
snoop82 wrote: pls do guide me
This[^] is the first step. Once you apply everything that is there, some people might help you. Until then, well, I don't think a lot of people would like to read all your code...
|
|
|
|
|
On top of that, this reeks of homework.
|
|
|
|
|
didn't i tell you you were a stupid idiot ?
well, i believe you'll trust me now when i give you posting advices.
otherwise, never forget i'll always be beyind your butt to kick you every time you'll abuse the forums
|
|
|
|
|
Is anybody familiar with SQLPassThrough? Is this just an old VB way of doing things, or does it also exist through VC++? If it isn't in VC++ what would the equivalent be?
|
|
|
|
|
I'm not sure if this is what you're referring to, but it seems this is related to direct
queries to a database, bypassing ODBC.
If so...
In the MFC ODBC classes, there's CDatabase::ExecuteSQL() and CRecordset::Open() with the executeDirect option.
For ODBC using the ODBC APIs, there's SQLExecDirect().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm writing a logging program for virtual COM port connected sensors which is later on going to communicate with a framegrabber for syncronisations purposes. For simplicity I wanted to run the program in a command window but MFC and iostream seems to have a hard time cooperating. I need access virtual serial ports and later on threading for the framegrabber (video input).
First: Is it a dead end to use iostream and a command window for my needs? Do the MFC components refuse running in a command window?
Second: If iostream and MFC should work together (I don't have any previous experience with MFC so I barely know what I'm speaking about) how do I get around my linking problems? I get the evil LNK2005 error, eg.:
nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in libcpmt.lib(newop.obj)
when I'm linking. It seems to be the "new" and "delete" operators which are the problem. I've already looked through the MS article on the topic (ID : 148652) but I still can't figure out how to get around it.
#include <afx.h>
#include <iostream>
,plus an almost empty main, gives me the error. What have I gotten wrong?
I'm using MS Visual Studio .NET 2003.
|
|
|
|
|
xjonil wrote: Second: If iostream and MFC should work together
They do. In dayly work with VS.NET 2003 and 2005.
I include the STL-stuff in stdafx.h, before including the MFC-stuff and there is no linker problem.
Please do a minimal test-program showing your problems and post it.
Are you perchance using new for a global static variable?
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
|
|
|
|
|
I'm at home now but I think it all boiled down to:
#include <afx.h>
#include <iostream>
void main()
{
std::cout << "test";
};
Now when I think about it I guess afx.h is a litte overkill. I got stuck on the solution proposed in the MS article. I used more specific include files like winbase.h to start with. I'm not sure if it caused the same problem.
|
|
|
|
|
Why don't you create a new console project and select MFC support, will that not fix the problem? Then you can diff to see what you're missing???
I got my to work just fine.
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Thanks alot!
I did get it to work but I still cannot figure out what the difference is. That was about what I started with. I guess I have to scrutinize every single character to see if I can produce the same error.
|
|
|
|
|
why don't you use a diff tool like windiff to find out what it different from you project (.vcprof) file and the one produced by with Wizard..will be a lot faster!!!
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Using GDI+, Visual C++ 2003.
When using the PenAlignment enumeration type to set line alignment before a drawing primitive like rect, or ellipse, it draws the outline etiher inset or centered on the outline boundary.
This works great for rectangles and ellipses with solid outlines.
However, I'm finding that when I draw rects or Ellipses with outline styles equivalent dashed or dotted with the alignment set to PenAlignmentInset, the results are horrible globs instead of the nice and neat dots and dashes when the alignment is set to PenAlignmentCenter.
typedef enum {
PenAlignmentCenter = 0,
PenAlignmentInset = 1
} PenAlignment;
MSDN states "If you set the alignment of a Pen object to PenAlignmentInset, you cannot use that pen to draw compound lines or triangular dash caps."
My guess is this refers to my issue but I'm not sure this is refering to a rect or ellipse primitive. If it is, problem identified. However, I thought I'd ask the opinion of the rest of you if your interpretation of the above MSDN statement refers to rects and ellipses.
Thanks in advance for opinions.
|
|
|
|
|
bob16972 wrote: MSDN states "If you set the alignment of a Pen object to PenAlignmentInset, you cannot use that pen to draw compound lines or triangular dash caps."
From reading the documentation, all it means is that to align "Inset", you have to draw something that has an inside and an outside. It seems to me that rects and elipses should work fine with that alignment.
Nathan
|
|
|
|
|
Nathan Holt at EMOM wrote: It seems to me that rects and elipses should work fine with that alignment
Unfortunately, the dots and dashes are disfigured blobs with inset. It's not nearly as noticeable with Ellipse and dash since one of the distortions is a kind've curving and it happens to distort in the same direction as the curve. However, an Ellipse with dot exhibits the distortion in a very obvious way.
With rects, it's easy to identify with dashes or dots.
|
|
|
|
|
can anyone tell about the difference between rs232 and rs422 in detail please..
thanks in advance
regards
sudhakar
|
|
|
|