|
Nowhere in the instructions posted does it say anything about constants. The only possible constants are the Minimum and Maximum diameters.
The only place you are instructed to use if/else if is in determining the number of slices.
All the code in the class could be done in a procedural way instead (without the class) using a method level variable diameter obtained from the user input. Just use the code in the relavant property getters.
|
|
|
|
|
|
Only partially - he still has to get the user input, validate it successfully (TryParse anyone?), display as instructed and then loop if required.
Also, hopefuly it will teach him something about OOP, so more of a lesson IMO. The stuff I've done is just simple maths - if he can't work that out for himself if he needs it again then he'll fail anyway - sooner rather than later.
|
|
|
|
|
Do you have an idea of where you are "stuck" here: is the difficulty figuring out how to write the if/then/else statements required ?
What's your goal here: just to get a working solution, or to explore and learn so in the future you can create solutions for many types of problems ?
best, Bill
"Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940
|
|
|
|
|
This is pretty straightforward, and having someone give you the answer is much less valuable than you going back and reading over the control structures part of your course so you can do it. Flow of control (if/else, switch and loops) are fundamental to programming (at least in a conventional language) and you need to understand them – when you do, this exercise is trivial.
Since I need to get some silliness out of the way before production code catches it, here is a tongue-in-cheek version of the logic (which will probably fail your test, heh):
double area = diameter * diameter * 0.25 * Math.Pi;
int slices = diameter < 12 ? 0 :
diameter < 16 ? 8 :
diameter < 24 ? 12 :
diameter < 30 ? 16 :
diameter < 36 ? 24 : 0;
if(slices == 0) throw new ArgumentException("Size out of range");
double sliceArea = area / slices;
Or how about
int[][] sliceMap = {{12, -1},{16, 8},{24, 12},{30, 16},{36,24}};
int slices = -1;
foreach(int[] mapping in sliceMap){
if(diameter < mapping[0]){ slices = mapping[1]; break; }
}
if(slices < 0) throw new ArgumentException("Size out of range");
Remember, don't hand something like this in . Go and read about if/else since that's clearly what the exercise is checking.
|
|
|
|
|
We are using below method to convert byte array into bitmap . we have successfully converted 16,24,32 etc. Pixel formats but we are facing issue while converting 4 and 8 pixel formats image is rendering in blur format and image starting and ending positions are changed.
///
/// Converting the raw data into bitmap
///
/// <param name="buffer" />Byte array of the image rawdata
/// <param name="nWidth" />Image width
/// <param name="nHeight" />Image height
/// <param name="nBitCount" />Image Pixel format
/// <returns>
internal Bitmap ConvertRawDataToBitMap(byte[] buffer, int nWidth, int nHeight, int nBitCount,PDIB pDIB=null)
{
Size imageSize = new Size(nWidth, nHeight);
PixelFormat imagePixelFormat = GetPixelFormat(nBitCount);
Bitmap bitmap = new Bitmap(imageSize.Width, imageSize.Height, imagePixelFormat);
Rectangle wholeBitmap = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
BitmapData bitmapData = bitmap.LockBits(wholeBitmap, ImageLockMode.WriteOnly, imagePixelFormat);
//Marshal.Copy(buffer, 0, bitmapData.Scan0, buffer.Length);
Marshal.Copy(buffer, 0, bitmapData.Scan0, bitmapData.Stride * bitmap.Height);
bitmap.UnlockBits(bitmapData);
bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
return bitmap;
}
///
/// Returns the pixel format from given bit count.
///
/// <param name="nPixelBitCount" />Pixel bit count example 4 or 8 or 16 or 24 ..etc
/// <returns>
private PixelFormat GetPixelFormat(int nPixelBitCount)
{
PixelFormat pixelFormat = PixelFormat.Undefined;
switch (nPixelBitCount)
{
case 4:
pixelFormat = PixelFormat.Format4bppIndexed;
break;
case 8:
pixelFormat = PixelFormat.Format8bppIndexed;
break;
case 16:
pixelFormat = PixelFormat.Format16bppRgb555;
break;
case 24:
pixelFormat = PixelFormat.Format24bppRgb;
break;
case 32:
pixelFormat = PixelFormat.Format32bppRgb;
break;
case 48:
pixelFormat = PixelFormat.Format48bppRgb;
break;
case 64:
pixelFormat = PixelFormat.Format64bppArgb;
break;
default:
pixelFormat = PixelFormat.Undefined;
break;
}
return pixelFormat;
}
Please help me to find the solution.
Thanks in Advance
Madhava Reddy, Madhu
|
|
|
|
|
Those formats are indexed, as the name implies. You need to provide a palette as well.
Where is the data coming from? Does it have palette information on the front? The pixel mismatch looks like you are not starting at the right place in the data array.
|
|
|
|
|
We tried using palette information eventhough we faced same issue.
Here is the code used to assign palatte
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
int
cval = 17 * i;
palette.Entries[i] = Color.FromArgb(0, cval, cval, cval);
}
bitmap.Palette = palette;
Instead of palette.Entries.Length we also tried giving 256.
Thanks for the reply.
|
|
|
|
|
We tried using palette information eventhough we faced same issue.
here is the code used to assign palatte
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
int cval = 17 * i;
palette.Entries[i] = Color.FromArgb(0, cval, cval, cval);
}
bitmap.Palette = palette;
Instead of palette.Entries.Length we also tried giving 256.
Thanks for the reply.
|
|
|
|
|
Hi Guys,
How to Programatically find the name application pool of an application.
Thanks
Yaju
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
hi Ravi
The article you mentioned gives me list of all application pools configured but what i am looking for is a way to programatically find out the application pool in which my application is residing.
Thanks
Yaju
|
|
|
|
|
If you scroll towards the bottom you'll see the example titled "I use this code snippet to get the application pool in which my website is running." Hope that helps.
/ravi
|
|
|
|
|
i need to get machine localization in my website.
i change my machine localization ("Regional and Language Options" control panel.)
and check with below code but always it shows as 'en_US'..
string strCluture = CultureInfo.CurrentCulture.Name;
what i need to do to get current localization. am i missing some setting or what?
|
|
|
|
|
Mugdha_Aditya wrote: i change my machine localization ("Regional and Language Options" control panel.)
and check with below code but always it shows as 'en_US'..
string strCluture = CultureInfo.CurrentCulture.Name;
what i need to do to get current localization. am i missing some setting or what?
Did you restart your application after you changed the setting? The CultureInfo is set for the app when it starts, and (luckily) doesn't change while running - even if the user changes it. The new CultureInfo should be displayed after you start your app.
Mugdha_Aditya wrote: i need to get machine localization in my website.
Care to explain a bit? You're fetching the culture of the webserver, not of the connected clients.
Bastard Programmer from Hell
|
|
|
|
|
Hey...
Thanks for the your reply.
I have restarted my application as well as my pc.
still its not applying selected culture.
|
|
|
|
|
Apart from CurrentCulture , there is also CurrentUICulture .
Since you're talking about a web site, do not forget to set the CurrentUICulture to the desired value whenever a new thread (!) is started - otherwise your web site will always run in the localization of your web server.
E.g.
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
Threads get their culture specific settings from the operating system, not from the thread they were started from.
|
|
|
|
|
i dontt want to set culture , i want to getculture info.
i have done below changes in page load but still its not working.
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
string strCluture = CultureInfo.CurrentCulture.Name;
strCluture returns en-US
|
|
|
|
|
how can i prevent my system in case of any theft also i want to block os installation?
|
|
|
|
|
You cannot protect any system completely.
|
|
|
|
|
Is that really a C# question?
Try a BIOS password. But since the thieves have physical access, they can always get around whatever you throw at them.
The first hit you get when you google BIOS password is a site with methods to reset it. Even if all of them fail, they could just replace the motherboard.
|
|
|
|
|
You can't. Well, not entirely true, but it would take a LOT more money and effort than it's worth. It'd be cheaper to buy a new laptop.
|
|
|
|
|
You could look into this Lojack for Laptops[^]. After one of my laptops was lifted I have used this with good effect. I haven't had any others stolen but I test occasionally, you can locate the laptop online. I have reinstalled the OS and still it works.
No comment
|
|
|
|
|
Lojack for Laptops can protect you to some extent, but it can do nothing if the hard drive is pulled out. If you are more concerned about the safety of the data, you'd better use encryption on the hard drive. Use something like TrueCrypt. It's free. Use encryption on all your removable media, too. These tend to vanish when you need them. Lojack will not be able to protect them.
|
|
|
|
|
loyal ginger wrote: but it can do nothing if the hard drive is pulled out.
Not entirely true. According to their website Lojack will still function if the drive is replaced and some laptops come with it preinstalled in the bios. I've used Lojack, but can't remember if I've replaced a drive while it was installed.
No comment
|
|
|
|