Saturday, May 9, 2009

Static cast in C++?

guys how can I use The static cast to write this C++ program:


Write a Program that prompts the user to input an integer between 0 and 35. If the number is less than or equal to 9, the program should output the number; otherwise, it should output A for 10, B for 11, C for 12, . . ., and Z for 35. (Hint: Use the cast operator, static_cast%26lt;char%26gt; ( ), for numbers%26gt;=10.

Static cast in C++?
The static_cast can be used to take a data type (like integer, float, etc) and cast it (aka convert it) to another data type like making an integer into a character like you need for this example.





The trick here is that the integer 35 isn't the ascii number for Z, so you will have to do a bit of addition before converting.





For example... if you look at an ascii chart you will notice that the capital "Z" is number 90.





static_cast%26lt;char%26gt;(90) will then give you the capital Z. So what we need to do is take the difference between 90 and 35... which is 55 and add it to every number the user types in greater than or equal to 10, then convert it.





So if the user entered.... 11, we would add 55 and get 66 then go static_cast%26lt;char%26gt;(66) to get a character "B". We then print out the character to screen.





As a side note, lower case letters start at 97 for "a" and go to 122 for "z" so that offset will need to be figured out if you want to use lower case.





I will let you figure that one out.





Hope this helps you out. Enjoy!
Reply:Please make few modifications to support your needs. The lines are broken.





To contact me mail me at m_gopi_m@yahoo.co.in.





I hope this is the program you are expecting.





//program for static casting.





#include%26lt;iostream.h%26gt;


#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





char static_cast(int);





void main()


{


int num;


char a;





clrscr();


cout%26lt;%26lt;"\n Enter a number: ";


cin%26gt;%26gt;num;





if(num%26gt;=0 %26amp;%26amp; num%26lt;=9)


{


cout%26lt;%26lt;"\n\n The given number: "%26lt;%26lt;num;


cout%26lt;%26lt;"\n\n The corresponding character: "%26lt;%26lt;num;


}


else if(num%26gt;9 %26amp;%26amp; num%26lt;36)


{


a=static_cast(num);


cout%26lt;%26lt;"\n\n The given number: "%26lt;%26lt;num;


cout%26lt;%26lt;"\n The corresponding character: "%26lt;%26lt;a;


}


else


cout%26lt;%26lt;"\n\n Cannot predict the value.";


getch();


}





char static_cast(int num)


{


int first='A'; //static casting is invoked here.


char a;


num-=10;


a=first+num;


return(a);


}


A) What is the task of a thyristor? b) How does a thyristor work? c) Thyristors are used in static frequency c

a) What is the task of a thyristor? b) How does a thyristor work? c) Thyristors are used in static frequency converters. How and for which purpose(s) are thyristors applied there?

A) What is the task of a thyristor? b) How does a thyristor work? c) Thyristors are used in static frequency c
Thyristor, semiconductor switch used chiefly in power-control applications. Also called a silicon-controlled rectifier (SCR; see rectifier),





it is a variation of the transistor. A thyristor is capable of producing large direct currents by rectification of alternating currents and can be automatically triggered “off” for specified periods of time. Thyristors are used in variable-speed electric motors, power supplies for electrochemical processes, lighting and heating control, and controllers for electric utility power systems.
Reply:This will tell you all you need to know.





http://en.wikipedia.org/wiki/Thyristor





..


Using Static for C++?

Write a C++ program that allows user to perform addition or subtraction continuously until the user decides to exit the program. Keep a counter in each of them to accumulate times the function is called





Can someone please help me with this. I have no idea where to start. I just need someone to explain to me what I need to do.





For example, I know I am suppose to have a function for both Addition and Subtraction, but I don't understand how I can make it so it loops itself and exits when the user wants to.





For the counter, I know I am suppose to use the static function, but I don't know where I should put it. Help please?

Using Static for C++?
use a do loop. Or a while loop. When the user enters a number such as a -1 make it break out of the loop. Put the counter inside the loop and make it add one to the counter everytime it goes through.





psedocode...





static int yourcounter





Do


{


//put addition and subtraction code here


//print the answer


// Add one to the counter








} (while num doesnt equal -1);





return;

gift

C# Static in Forms?

Hey guys, I've figured out how to make my form controls accessible to a class by changing the controls to static in my form designer code. The problem is that whenever I do this, the control disappears from the form designer where it shows you all the controls and where you can drag and drop things(not sure what this is called?) Is there any solution to this?

C# Static in Forms?
Not sure but can you make it Public Shared


Visual C# 2008 "static", "void", and "string[] args"?

Hi,


I just started to learn visual C# 2008, I had no previous experiences in programming and I don't understand these codes: "static", "void", and "string[] args". Anyone can explain? Thanks!





P.S I searched in MSDN but it just confused me more..

Visual C# 2008 "static", "void", and "string[] args"?
i'll start with void


void means that the functions doesn't return any thing to the caller


ex.


void sayhello(string name)


{


Console.Writeline("helloo {0}",name);


}


whn i call this function the function will print the hello messege and exits there is nothing returned


bu if i define a function like this:


int sum(intx , int y)


{


z=x+y;


return z;


}


this means that the function have a return type of int(intger)


and when i call this function it returns an intger number


--------------------------------------...


string[] args


when u run a program from a command line u can use arguments with it


ex.


c:\%26gt;hello.exe jack NY


jack and NY r called arguments


so u want to have access to this arguments in ur program


these arguments r stored in the array that is defined by string[] args


so jack will be in args[0] and NY will be in args[1]


--------------------------------------...


static


this 1 is alittel difficult


C# is and object orianted language, that means every data and function in ur program must be stored in an object and this object needs some function to create it


but if that is true then how the 1st object can be created if it needs a function to create it and there r no functions allowed outside an object (the problem of the egg and the chicken, which is first)


so the ppl that made C# "microsoft" decided that they will allow a special type of functions to work without needing an object


and to mark this function we write static before the function name


that means this function don't need an object to run


static void main(string[] args)


this means that this function will run with no need for an object and won't return any thing and stores the command line arguments in string[] args


i hope u didn't get lost in the middle


note :if u want more info then ask again and i'll try to answer u
Reply:static: it means that the variable or function is globally available, meaning any piece of code can access it (depending on access modifiers, a private or protected static member of a class would only be accessible within that class). Also is important to note is that static variables are allocated even before the main function (the entry point) is called, and the order of their allocation and deallocation cannot be determined. You would typically use static variables and functions for anything that needs to be accessed anywhere. The Main function is static because the entry point can't be tied to an object.





void: it's an object type of sorts, specifically not an object. It means nothing, literally. If you see a void function, it means it doesn't return anything.





String[] args: this is a variable declaration, specifically an array (that's what the [] means, if their was a number between the [] it would indicate the number of elements in the array). It is an array (or collection) of strings whose size is not specified.
Reply:Try to read a C# tutorial or you'll be lost every program that you try to create:





http://www.csharp-station.com/Tutorial.a...


A.Network Address Translation (NAT) b.Private network addresses c.Static and Dynamic IP Addressing?

1) Explain the following in details. a.Network Address Translation (NAT)


b.Private network addresses


c.Static and Dynamic IP Addressing


2) A company called Terudo wants to install a local area network. It has five departments. It has purchased 80 computers and each department is expected to grow. However this company wants to segment its network according to department, with equal number of pc’ so far it has. Choose any class C address and clearly indicate the number of IP addresses, available and non-usable in each subnet. Show your working clearly.

A.Network Address Translation (NAT) b.Private network addresses c.Static and Dynamic IP Addressing?
Argh, another MCSE turd who thinks he can make money in IT without actually knowing anything about computers....