|
I need help on the coding for this project. Is there any examples or coding for this program...... Write a program in C++ to simulate the performance of the SSTF and the C-LOOK disk scheduling algorithms shown in class. We assume the disk system supports track numbers ranging from 0 (the outermost track) to 49 (the innermost track).
The following shows a scenario of running the program, where user’s inputs are in boldface.
>smi3456p3 {an executable program}
please enter a sequence of track numbers:4 40 11 35 7 14
where is the current position of the arm?15
what do you want to do?
1 = SSTF
2 = C-LOOK
3 = quit
1
the history of arm movement is: 15, 14, 11, 7, 4, 35, 40
what do you want to do?
1 = SSTF
2 = C-LOOK
3 = quit
2
what is the direction the arm is currently moving?
1 = toward the innermost track (i.e. 0)
2 = toward the outermost track (i.e. 49)
2
the history of arm movement is: 15, 35, 40, 4, 7, 11, 14
what do you want to do?
1 = SSTF
2 = C-LOOK
3 = quit
3
>
brandy smith
|
|
|
|
|
I don't think many people here want to do your homework for you. The best advice I can give you is to write down how to solve the problem on paper, then realize what you did to solve the problem and simulate that when you write code. I've studied the disk scheduling algorithms myself, they aren't too difficult and I think you can do it yourself.
|
|
|
|
|
Why does this code compile? It crashes at runtime
int test(LPCWSTR p)
{
return wcslen(p);
}
int test2()
{
return test(L'');
}
.
thanks!
|
|
|
|
|
Are there any warnings from the compiler?
It's tough to tell from the code listed but it looks like you are casting a character to a string pointer. It's pretty unlikely that the string is going to be null terminated. That's what I'd be looking at.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Chris Meech wrote: it looks like you are casting a character to a string pointer
I am not casting, L is the notation to indicate its a unicode string. To me this is a compiler bug. More over the following code gives an error when compiled:
<br />
int test3(LPCSTR p)<br />
{<br />
return strlen(p);<br />
}<br />
<br />
int test4()<br />
{<br />
return test3('');<br />
}<br />
<br />
I am using VS6. Can someone check if this compiles on VS2003 too?
thanks!
|
|
|
|
|
It compiles because it's a valid code.
why it crashes ? well, p is NULL so that why it crashes.
I assume the L macro ( is it a macro or a MS specific keyword ? ) cannot expand a single char into a wide char string.
are you certain you're not wanting to do this instead ?
int test2()
{
return test(L"");
}
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
You are right, I had typed single quotes by mistake, and that proved costly. If only the compiler had caught it life would have been little simpler.
I dont know what L'' resolves to? There can be an empty string, but empty character doesnt make any sense. It is not clear how this compiler thinks.
thanks!
|
|
|
|
|
First, the L prefix causes the complier to treat the following constant string or character as a wide-version. So, L"Test" creates a wide string, and L'3' yields a wide character.
The empty character constant '' yields a value of zero. Since the function was expecting a pointer, and a value of zero can be used for a pointer (it is the same as NULL in C++), that is what happened and why the code compiled correctly.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Today, we have an informational dialog where the information is displayed in
a RichText control. The only action for the user is to press the OK button
to dismiss the dialog.
My desire is to enhance this dialog by adding a 'Go To' button where the
user would select one of the informational items in the list, press the 'Go
To' button, the dialog would disappear, and then the 'go to' action occurs.
I still need to display the information using RichText.
Following an example, I attempted to create a custom CListBox control where
the items in the listbox would be displayed using the CRichTextCtrl. The
custom CListBox control contains owner methods of DrawItem and MeasureItem.
The first draft for DrawItem is included. This code appears to work but is
far from perfect. It lacks code for item selection and in my sample code I
can get it to write outside of the boundary of the control. Furthermore, I
am not sure what needs to be done for MeasureItem method.
void CRichEditListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle (lpDrawItemStruct->hDC);
if (lpDrawItemStruct->itemID != -1)
{
COLORREF TextBkClr = SysColor (COLOR_WINDOW);
CString Text;
GetText (lpDrawItemStruct->itemID, Text);
CRect rect;
GetItemRect (lpDrawItemStruct->itemID, rect);
// Format the text and render it
UINT Left = ::MulDiv (rect.left, 1440, pDC->GetDeviceCaps (LOGPIXELSX));
UINT Top = ::MulDiv (rect.top, 1440, pDC->GetDeviceCaps (LOGPIXELSY));
UINT Right = ::MulDiv (rect.right, 1440, pDC->GetDeviceCaps (LOGPIXELSX));
UINT Bottom = ::MulDiv (rect.bottom, 1440, pDC->GetDeviceCaps (LOGPIXELSY));
CRect Rect (Left, Top, Right, Bottom);
FORMATRANGE fr;
fr.hdc = pDC->m_hDC;
fr.hdcTarget = pDC->m_hDC;
fr.rc = Rect;
fr.rcPage = Rect;
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
UINT StreamType;
if (Text.Left (6) == "{\\rtf1")
StreamType = SF_RTF;
else
StreamType = SF_TEXT;
EDITSTREAM es =
{
(DWORD)&Text, 0, EditStreamCallBack
};
m_pRichEditTemp->SetSel (0,-1);
m_pRichEditTemp->SetBackgroundColor (FALSE, TextBkClr);
m_pRichEditTemp->Clear ();
m_pRichEditTemp->StreamIn (StreamType, es);
m_pRichEditTemp->FormatRange (&fr, TRUE);
// Update the display with the new formatting
CRect rcClient;
m_pRichEditTemp->GetClientRect (&rcClient);
m_pRichEditTemp->DisplayBand (&rcClient);
}
}
I have examined the internet and information is scarce. My hope is that
some one can point me in the correct direction or can suggest another
approach.
Thank you for your support.
Dan
|
|
|
|
|
Hy.My problem is i dont know how to make gif animation in dynamic way with CxImage.
I found a static solution in the MFC demo program,but i need a dynamic one,
to allocate the memory dynamic.
thanx the help
|
|
|
|
|
Hi All,
I have a small app that is designed to open an Access database file (.mdb) from a normal CFileDialog. Each database has one table and has the exact same fields in it. My question is how can I open a CDatabase and connect to the CRecordset with any of the database files I select? When I created the new CRecordView and CRecordset a blank default .mdb file was used via ClassWizard.
If the default sql string is empty the "Select Database" dialog appears, but I want to select a database from my apps menu handler.
I have a CRecordView derived class (CEditorView) that will edit (add, delete, etc) the records. Unfortunately, most of the tutorials are for "reading" records only.
Hope this make sense. Thanks.
Mark
|
|
|
|
|
Take a look at this for classes to allow you to read and write to databases. There are also examples on how to edit records.
|
|
|
|
|
Thanks, but I am using ODBC:CRecordset/CDatabase for this app.
Mark
|
|
|
|
|
Mark F. wrote: My question is how can I open a CDatabase and connect to the CRecordset with any of the database files I select?
You'll want to use a DSN-less connection. This article shows a brief example.
Mark F. wrote: I have a CRecordView derived class (CEditorView) that will edit (add, delete, etc) the records. Unfortunately, most of the tutorials are for "reading" records only.
Editing/adding/deleting is no big deal. Just use CRecordset 's methods. For example:
rs.m_pDatabase->BeginTrans();
TRY
{
rs.Open();
rs.AddNew();
rs.var1 = 123;
rs.var2 = "Name";
...
rs.Update();
rs.m_pDatabase->CommitTrans();
}
CATCH(CDBException, pDBException)
{
rs.m_pDatabase->Rollback();
}
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
David,
I will read the article you posted. Thanks for the help!
Mark
|
|
|
|
|
Hi,
I need a virtual 'Video Capture Source'. I could make use of DirectX Filter to create a video capture source. But i am not getting how it is implemented in VC++. Can any example or link provide way to Register Filter created in VC++ as 'Video Capture Sources'
Thanks,
Jariwala Vishal
-- modified at 23:28 Thursday 10th November, 2005
|
|
|
|
|
Hi everybody. I stumbled today on a rather intriguing issue. I got a DLL which is loaded via a hook in Explorer.exe. In that DLL I got the following HFONT array.
#pragma bss_seg("Share")<br />
<br />
HFONT *hfntarrLabels;<br />
<br />
#pragma bss_seg()
I need it in a #pragma 'cause I use another application to set its elements. Anyway... the problem is that when I try to clean it up, free the memory, explorer.exe crashes. This is how I create it, before hooking:
hfntarrLabels = new HFONT[10];<br />
hfntarrLabels[0] = CreateFont(...)
And this is how I free it, during the hooking:
delete []hfntarrLabels; // <-- crashes
And this, also crashes:
SelectObject(hdcMem, hfntarrLabels[0]);
Even though as far as I can see, the hfntarrLabels[0] has a non zero value.
Ideas anybody?
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas wrote: hfntarrLabels = new HFONT[10];
hfntarrLabels[0] = CreateFont(...)
From the code, it looks like you are allocating memory in one process and trying to access it from another. If that's the case, it's not going to work, since each process has its own virtual address space and an address in one is meaningless to another.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
But I'm using #pragma. Wasn't that supposed to fix such issues? Sorry, I'm a bit of a beginner in this memory allocation business ::- D. Anyway... I tried at least 10 combinations and it crashes and crashes and crashes all the time. I'm going nuts here ::- (. Explorer.exe just won't let me delete (free) an array I created before and crashes. Even if I created it from my DLL Loader process, it's still the same DLL right? It gets attached to Explorer.exe.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
I'm no expert in #pragma directives, but a quick Google search showed that
#pragma data_seg("SHARED")
is the right way to share *data* between applications loading the same DLL.
Axonn Echysttas wrote: Even if I created it from my DLL Loader process, it's still the same DLL right? It gets attached to Explorer.exe.
It's the same DLL, but it gets mapped to different address spaces everytime it's loaded by a process. In short, a memory addresses are specific to a process, so calling new in one process and delete on the other will definitely result in a crash.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Can some one tell me steps to be taken to rename a project.
|
|
|
|
|
As far as I remember, for VC++ 6 Rename your DSW file and your DSP file. If the environment asks you for the location of the DSP file upon loading the DSW, simply browse for it and then save all files. For .Net, might be the same but I'm not sure. You might need to rename the cppproj file. Hope that helps.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Assuming your project name is "blah", open up BLAH.DSP and BLAH.DSW in your favourite text editor and go to the first line on the DSP file, which will look like:
# Microsoft Developer Studio Project File - Name="blah" - Package Owner=<4>
Then do a global + all files search'n'replace for the string "blah" with the name of your new project (let's try "halb"). Save and exit. Then rename BLAH.* to HALB.* at the command prompt (you *are* using a good one like 4NT, aren't you? ) and away you go. Take 20 seconds and works.
|
|
|
|
|
HI all ,
Are there any restrictions (size wise) when using this function
my bouncechecker screams when the size of the sent buffer is greater then 6648 bytes
anyone ?
thanks
|
|
|
|
|
ita_cas wrote: bouncechecker
what's that ?
looking at the MSDN[^], i cannot see any restriction of this type...
maybe you overrun your buffer ?!
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|