|
193344 wrote: y=( (y2-y1)/(x2-x1) ) * incx+y1;
this line will always be executed at least once, as it sits inside a do-while loop, without any precondition. And for vertical lines, x1 equals x2, so the division will fail.
Your code isn't very well structured; what you should do is provide a general line drawing implementation, and one (or more) specialized ones; then have conditional tests organized such that exactly one implementation gets executed, depending on the input values.
|
|
|
|
|
Below is what my driver looks like I'm trying to read/write data from a singly linked list to random access file in c++ but thus far I'm unable to do so....any help in solving this problem would greatly appreciated.
#include"List.h"
#include "Employer.h"
void InitialEmployerRan()
{
int count; //counter for loop
int me=20; //max number of employees
ofstream RanFile("Employer.dat",ios::out |ios::binary);
if (RanFile)
{
//Enter the total number of employees
cout <<"\nEnter maximum number of emplyees ";
cin >> me;
//create an object with default data
Employer obj;
//Initialise employees file with me records
for(count = 0; count < me; ++count)
{
RanFile.write(reinterpret_cast <const char="" *="">(&obj),sizeof(Employer));
}
} else
{
cerr <<"file was not fond";
}
}
//display program instruction to user
void instruction()
{
cout <<"Enter ont of the following:\n"
<<"1 to insert at front\n"
<<"2 to delete from front\n";
}//end function instruction
template<typename t="">
void TestList(List<t> &listObject)
{
instruction();//display instruction
int choice;//store user choice
T value;
Employer emp;
string fname,lname,address,pos,Cname,email ;
int cel, hom, id;
do{
cout <<"enterchoice";
cin >> choice;
system("cls");
switch(choice)
{
case 1:
cout<<"Enter Data: "<<endl;
="" cout<<"id:";
="" fflush(stdin);
="" cin="">> id;
cout <<"\nEnter employeer's first name ";
fflush(stdin);
cin >> fname;
fflush(stdin);
cout <<"\nEnter employeer's last name ";
fflush(stdin);
cin >> lname;
cout <<"\nEnter employeer's jop Title ";
fflush(stdin);
getline(cin,pos) ;
cout <<"\nEnter employeer's email ";
fflush(stdin);
cin >> email;
cout << "\nEnter name of company";
fflush(stdin);
getline(cin,Cname);
cout << "\nEnter employeer addreess";
fflush(stdin);
getline(cin,address);
cout <<"Enter Employer cell number ";
fflush(stdin);
cin>>cel;
cout <<"Enter Empolyer home number ";
fflush(stdin);
cin>>hom;
listObject.insertInFront(Employer(fname,lname,address,pos,Cname,email ,cel,hom,id));
//listObject.print();
break;
case 2:
if(listObject.removeFromFront(value))
cout << value <<" remove from list\n";
listObject.print();
break;
}
}while(choice < 3);
CreateList(listObject,id);
DisplayEmployeeRan(listObject);
}
template<typename p="">
void CreateList(List &listObject2,int i)
{
Employer emp;
fstream RanFile("Employer.dat",ios::in | ios::out |ios::binary);
if (RanFile)
{
while(!listObject2.isEmpty())
{
RanFile.seekp(sizeof(Employer) * (i- 1));
RanFile.write(reinterpret_cast< const char *>(&emp),sizeof(Employer));
cout<<"file was updated";
break;
}
}
else
{
cerr<<"Error the file was not found";
}
}
template<typename t="">
void DisplayEmployeeRan(List<t> &listObject3)
{
char ans; //answer to store 'y' or 'n'
Employer emp;
int in;
ifstream RanFile("Employer.dat",ios::in |ios::binary);
if (RanFile)
{
while ( !listObject3.isEmpty( ))
{
cout <<"\nEnter employee's id number to"<< " display ";
cin >> in;
RanFile.seekg(sizeof(Employer) *(in - 1));
RanFile.read(reinterpret_cast<char *=""> (&emp),sizeof(Employer));
//if not eof show data
if(! RanFile.eof())
{
//Display the processed
// info for the employee
listObject3.print();
} cout << "Display another "<<"employee's information? [y/n] ";
fflush(stdin);
ans = ' ';
while (ans != 'y' && ans != 'Y'
&& ans != 'n' && ans != 'N')
{
ans = _getch();
} cout << endl;
if (ans == 'n' || ans == 'N')
{
exit(1);
}
}
} else
{
cout <<"Error - random files could not be opened.";
}
}
int main()
{
// InitialEmployerRan();
List <employer> EmpList;
TestList(EmpList);
system("Pause");
return 0;
}
|
|
|
|
|
djgmad wrote: ...but thus far I'm unable to do so
Which means what exactly? Which part specifically are you having trouble with? Focus on just that part, and remove, or comment out, other irrelevant code.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I'm having problem with both writing and reading the linked list to the file. To be honest I don't know which is giving me be problem writing or reading...Any help in creating codes that read and write to and from a liked list would be appreciated.
//code used for writing to the linked list
template<typename t="">
void DisplayEmployeeRan(List<t> &listObject3)
{
char ans; //answer to store 'y' or 'n'
Employer emp;
int in;
ifstream RanFile("Employer.dat",ios::in |ios::binary);
if (RanFile)
{
while ( !listObject3.isEmpty( ))
{
cout <<"\nEnter employee's id number to"<< " display ";
cin >> in;
RanFile.seekg(sizeof(Employer) *(in - 1));
RanFile.read(reinterpret_cast<char *=""> (&emp),sizeof(Employer));
//if not eof show data
if(! RanFile.eof())
{
//Display the processed
// info for the employee
listObject3.print();
}
cout << "Display another "<<"employee's information? [y/n] ";
fflush(stdin);
ans = ' ';
while (ans != 'y' && ans != 'Y'&& ans != 'n' && ans != 'N')
{
ans = _getch();
}
cout << endl;
if (ans == 'n' || ans == 'N')
{
exit(1);
}
}
}
else
{
cout <<"Error - random files could not be opened.";
}
}
|
|
|
|
|
djgmad wrote: I'm having problem with both writing and reading the linked list to the file. To be honest I don't know which is giving me be problem writing or reading...Any help in creating codes that read and write to and from a liked list would be appreciated.
Use the debugger to single step through your code to see what it is doing. Always break larger problems down into smaller ones.
djgmad wrote: ifstream RanFile("Employer.dat",ios::in |ios::binary);
if (RanFile)
This is not likely what you intended to do since RanFile will be non-zero whether the file was opened or not.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
You could start by formatting your code properly by the use of <pre> tags; click the code button. Then try explaining exactly which part of the code has the problem and what that problem is.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I'm having problem with both writing and reading the linked list to the file. To be honest I don't know which is giving me be problem writing or reading...Any help in creating codes that read and write to and from a liked list would be appreciated.
//code used for writing to the linked list
template<typename t="">
void DisplayEmployeeRan(List<t> &listObject3)
{
char ans; //answer to store 'y' or 'n'
Employer emp;
int in;
ifstream RanFile("Employer.dat",ios::in |ios::binary);
if (RanFile)
{
while ( !listObject3.isEmpty( ))
{
cout <<"\nEnter employee's id number to"<< " display ";
cin >> in;
RanFile.seekg(sizeof(Employer) *(in - 1));
RanFile.read(reinterpret_cast<char *=""> (&emp),sizeof(Employer));
//if not eof show data
if(! RanFile.eof())
{
//Display the processed
// info for the employee
listObject3.print();
}
cout << "Display another "<<"employee's information? [y/n] ";
fflush(stdin);
ans = ' ';
while (ans != 'y' && ans != 'Y'&& ans != 'n' && ans != 'N')
{
ans = _getch();
}
cout << endl;
if (ans == 'n' || ans == 'N')
{
exit(1);
}
}
}
else
{
cout <<"Error - random files could not be opened.";
}
}
|
|
|
|
|
Please edit your message and format the code properly as previously suggested. Unformatted code like the above is not easy to read.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
See here. It may not be exactly what you are looking for, but it might point you down the right path.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
> Hello., I followed your wave recoding and playing code from this Voice Recording/Playing back using simple classes[^]
>> That helps me a lot
>> Now i want to write buffer data to a wave file
>> Can any one tell me how to write a wave file from buffer
|
|
|
|
|
Member 8701235 wrote: >> Can any one tell me how to write a wave file from buffer
If you are using MFC, check out CFile . If you are using Win32, check out WriteFile() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
When I start a new Win32 project how to load picture in the white window, say with open file dialog (selected from menu above) :?:?:?:?
|
|
|
|
|
Have you tried calling BitBlt() in your WM_PAINT handler?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I have an app, developed in VC6.0 which uses a Date Time Picker control to display the time in a CTime object using HH:mm:ss format. This works OK on XP based PCs but when I run it on Windows 7 (32 bit) it displays the wrong time: A time of 00:00:10 is displayed as 16:00:10.
The Date Time Picker control is mapped to the CTime object using MFC DDX_DateTimeCtrl. The time value in the CTime object seems to be correct.
Has anyone come across this kind of thing before?
TIA 
|
|
|
|
|
Sounds like the regional (i.e., locale) settings are different between the two machines.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
hello guys... plz first consider this code.
<pre lang="c++">
void CMoveWindowDlg::MoveMyWindow()
{
CWnd* wind = GetDlgItem(IDC_UPDOWN); // Current button to which: this event handler is bound
ASSERT(wind!= NULL);
wind->GetWindowRect(&rect);
r.top = rect.top;
r.left = rect.left;
r.right = rect.right;
r.bottom = rect.bottom;
int height = rect.Height();
int width = rect.Width();
wind->MoveWindow(100, 100, width, height, 1);
}
</pre>
<b>1 - </b> Here I get the location and size in two things - <b>RECT r</b>, <b>CRect rect</b>. When I click on this button, it takes my button to the specified point. The problem is: if there is some other control already at that point like EditBox, this button will not work and the EditBox will come on top of it.
<b>2 -</b> I use another button to place this button back on the previous location by providing the location which I stored in <b>Rect r</b>, like this..
<pre lang="c++">GetDlgItem(IDC_UPDOWN)->MoveWindow(&r,1);</pre>
But unfortunately, this also does not place the buttun at its original place.
Problems are specified so whats wrong with this code?
|
|
|
|
|
1 And what is your question?
2 This:
overloaded Name wrote: wind->GetWindowRect(&rect); will give you screen coordinates while this:
overloaded Name wrote: GetDlgItem(IDC_UPDOWN)->MoveWindow(&r,1);
expects the coordinates to be in "client of the parent window space". Use e.g. ScreenToClient to convert screen coordinates to client coordinates of the parent window.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Hi!
I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism,
Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
|
|
|
|
|
Well I mysellf am new to tech world but I think it depends upon feature that a particular language supports. To print something on screen you use
- printf("The Sum is: %d", sum)
in 'C'. But in C++, you dont have to worry about the datatype like
- cout<<"The Sum is: "<< sum;
So you see some laguages are easier to develop with. Moreover, almost anything that can be done in C++ can also be done in Java. But Java does not support pointers while C++ does. So does this make C++ a better / worse choice than Java? NO: it all depends on the problem that we are going to address and of course, our own choice as well.
|
|
|
|
|
|
pix_programmer wrote:
Any other answers?
Thats is rude. I dont think I am going to get paid for sharing my thoughts with "your excellency". 
|
|
|
|
|
overloaded Name wrote: Thats is rude.
Actually that's not so rude, because your answer is apparently incomplete.
Veni, vidi, vici.
|
|
|
|
|
but I think it depends upon feature that a particular language supports.
Thats what I wrote in first line. I think I should have replaced this line with: "Features such as OOP". I just said a more generalize sentence. I assumed OP knew that C++ was named "C With Classes" at first, but was renamed later.
CPallini wrote:
Actually that's not so rude
OK That is rude to some extent. Yet I confess my answer may have been incomplete and did not help, so no more replies from my side.
|
|
|
|