Tuesday, July 14, 2009

To use the library function rand in c program?

i want to create a timetable for 5 days and 8 periods with 10 subjects.to select the subjects randomly i used rand function.but this generates the same number more than one time for a day.how could i avoid it????also i want the individual number to be generated for a particular number of times per week.plz help me.......................

To use the library function rand in c program?
The rand() function generates random numbers but this does not mean that it'll generate all different numbers.





Consider the following iteration :





randomize();


for(i=0;i%26lt;10;i+=1)


{


printf("%d",rand()%10);


}





the program will print random numbers under 10, 10 times. This program code does not imply that 8 may not be repeated twice.





Now, coming to your program, each day has 8 periods to which any of the 10 subjects without any repetitions have to be applied.





Make an array of size 8 denoting the periods per day like ( per[8]);





now assign the first period as





per[0]=rand()%10;





now for the subsequent assignments compare with the previous elements of the array. If any of them are equal to the value currently assigned, run the randomize statement again. In this way, you'll be able to assign all distinct values to the array.





hope this helps.
Reply:Which compiler are you using, and for which operating system?


If you're using Borland Turbo C++ 3.0 for DOS, then you can simply view the example code in the IDE's built-in help file.





I don't want to do your homework for you, so I'll just help you with the rand() function.


When creating random numbers, you must first 'seed' the random number generator, otherwise your program will always come up with the same 'random' numbers. In 16 bit compilers, rand() returns a signed 16 bit random number, and in 32 bit compilers, rand() returns a signed 32 bit random number. You can modify the the line that calls rand() in order to modify the output number to suit your needs. Just be careful with the numbers when you use rand(). For example, if you're using a 16 bit compiler, you must remember that rand() can only give a random number up to +32767. But you can go up to +65535 if you use casting to make a variable an unsigned one.





Example:


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


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


time_t t;


int num;





int main(void)


{


srand((unsigned) time(%26amp;t)); // seed random number generator





// Random number between +1300 and +1400:


num=(1300+rand()%1400);


// Random number between +200 to + 2000, in multiples of 10:


num=((200+(rand() % 180)*10));


// Random number between +1 to +50:


num=(1+rand() % 50);





return 0;


}


Look in your compiler's help file and information on the Internet for more sample code.
Reply:Well, I know c++ and c are different but the concept is the same. Run the rand function in an if loop for the day, the loop guidelines should say something like





rand=p8





if (rand=p1,p2,p3,p4,p5,p6,p7,)


{rand=p8}





that way the period is changed until the rand compiles a different number. Not sure what the rand code looks like in c though. i mostly used srand which created a number based on an algorithm in the computers date
Reply:The easiest way to ensure you don't get duplicates, is to check each time for duplicates, and get a new random number if one crops up. If you're doing it this way, it may be easier to store an index giving you a quick way of looking up a number which has already been used.





However, if you want to ensure that you never duplicate a day/period, it may be easier to walk through the days and periods and randomly pick the subject (rather than randomly pick all the day, period and subject).





If you want to limit the number of occurrences of a subject, then keep a tally of subjects and get a fresh number if you don't like the one you've been given. Each time you get an acceptable subject, reduce the tally. If the tally reaches 0, the subject isn't acceptable again.





For example:





/* define the maximum number or times we are prepared to loop to find an availiable subject before giving up */


#define NUMBER_OF_ATTEMPTS 10





/* define the number of times each subject may be picked, always make the 0th item more than the number of periods in a week, to be sure there is something that can always be picked. Each number corresponds to the number of times you'll allow a particular subject (ie 8 for subject 1 and 6 for subject 3 */


int subject_tally[]={9999, 8,8,6,6,4};





/* The array containing your final data*/


int picks[5][8];


/* The loop counter variables */


int day, period, subject, attempts;





/* initialise random seed */


srand (time(NULL));





/* loop through each period of each day*/


for (day=0; day%26lt;5; day++)


{


for (period=0; period%26lt;8; period++)


{


attempts=0;


/*attempts loop prevents run away */


while (attempts++%26lt;NUMBER_OF_ATTEMPTS)


{


subject = rand() %6 ; /* gives a random number between 0 and 5 */


/* only consider the subject if it still has an excess of available periods*/


if (subject_tally[subject]%26gt;0)


{


picks[day][period]=subject;


subject_tally[subject]--;


/* Leave this while loop if a subject was successfully picked*/


break;


}


}


/* if we ran out of attempts, then make it a free period */


if (attempts %26gt; NUMBER_OF_ATTEMPTS)


{


picks[day][period]=0;


}


}


}


I want to get a c++ code contaning a function on library system?

c++ fuction

I want to get a c++ code contaning a function on library system?
void f() {





}


Can anybody suggest a site where i can find a program on Library management in C++?

I like plograming ,


about ,


Imeen,


%26lt; %26gt;


%26lt; %26gt;


%26lt; .


%26lt; %26gt;





%26lt; %26gt;








............................(%26lt; %26gt;)


ew


ew


ew


%26lt;#/////////////////////////////#%26gt;


%26lt; %26gt;

Can anybody suggest a site where i can find a program on Library management in C++?
Managing c library?
Reply:You can try the following site


http://www.vyomworld.com/source/code.asp...


or you can read the book containing different project by Sumita Arora see their publication list.
Reply:Every compiler package has its own librarian.


Read your compiler documents.

long stem roses

Is it possible to define new functions with the same names as standard library functions in 'C' language?

Yes. That's called "overloading."

Is it possible to define new functions with the same names as standard library functions in 'C' language?
Yes it is possible. However, the reason the library exists is to stnadardize many of the common elements required for writing code, so that people were not re-inventing the wheel each time they wrote a program in C.





That said, several string input functions--such as gets() and scanf()--are the source of many buffer overflow attacks by hackers. So it might be a good idea to re-write the headers, and use your own custom library of more secure functions. That way you will have more robust and secure code in your programs.
Reply:Sure. Just don't use the standard library header directly.
Reply:No, it is not possible.


Not if you link your program with standard library and use standard headers.





Overloading exists only in C++ and allows to define new functions with the same names, but different parameter types. Overloading does not apply to C language and standard C library functions.





You can't redefine, for example, function printf() or atoi(); If you make C function with the same name and parameter types, the program won't link because of naming conflicts.





In C++ program (but not C) you can make function with the same name as library function - like atoi() for example, but it has to have different parameter types, and it won't replace the original library function.


Does Anybody Know What Is The Address For The Congress Library Washington D.C.?

http://www.loc.gov/index.html





The Library of Congress


101 Independence Ave, SE


Washington, DC 20540


How to copy songs from i tunes library to a c.d?

hi friends

How to copy songs from i tunes library to a c.d?
first you have to make sure you have a blank cd then you make yourself a playlist by clicking on the songs you want and dragging them to the left side once you have your playlist made you go to it and click on burn cd in the upper right hand corner where you music shows up when you play it then you let it burna dn your done


Can someone give me the code for library managment project in c language.. the projest must be simple..?

have to make a simple project in c language using file management wit a little of graphics.. it should be very sipmle and easy to understand.. if someone cud help me.. plz send me the cop of the code.. thnx..

Can someone give me the code for library managment project in c language.. the projest must be simple..?
Do your own coursework. You WILL get caught if you don't.





Rawlyn.

gifts

How do I move my Itunes-program, library etc... from my C -drive (full) to the D -drive (99%empty)?

How do you move programs from your C drive to the D drive?

How do I move my Itunes-program, library etc... from my C -drive (full) to the D -drive (99%empty)?
Just click the folder from your C:\ drive and hit CTRL X and open your D:\Drive and hit CTRL V.
Reply:D drive is probbly a recovery drive....check how big it is.
Reply:if they are setups.. copy paste would be good...lol.


but i think u talking about the installed stuff..





its way too difficult man,, registeries, etc, etc, etc..





simplest way would be reinstalling all those stuff in D:\





about the library, i hope there may be a option of exporting it,


install itunes on d:\ and then again import it..





I hope it was worth..


What is another name for a library file in 'C'?

Never heard of any other name. However, I do know that they have been called "static" library files because of their unchanging nature in the past. Now, most software uses DLL files, or Dynamic-Linked Libraries (Microsoft seems to love them...) to take care of various parts and pieces of code.

What is another name for a library file in 'C'?
header file would be another option. library is probably universal name for that particular name in c. but awesome question. i'll have to ask my teacher this question.
Reply:I don't think there is a synonym for a c library file. Never heard it called something else. It's been confused with header and object files by newbs, in error...





But still, you might find what you're looking for at the link below..
Reply:Library files, those containing object modules generated from C source or other compiled source, are also known as archive files. The term archive originates from early versions of UNIX, and is still the commonly used term to reference them by UNIX programmers today.





The archive command (ar) is used to manage archive files which are usually named libXXX.a where XXX is the nature of the library. Common archives are:


libc.a -- standard C library


libm.a -- standared Math library


libsocket.a -- socket





If an archive is referenced on the compile command line, the needed object modules from the archive is statically linked into the resulting binary (executable in MSDOS speak). If shared object archives are referenced at the time a binary is created, the references are noted in the binary, but not stored in the binary file itself. This results in the binary being a smaller file, but also requires that the shared object archive(s) be present on the computer where the binary is to be loaded and executed.





Shared object archvies have a name that has the form libXXX.so.v where XXX is the same type name that libXXX.a has, and v is the version number. Version numbering is important with shared objects as a binary created to work with libiconv.so.2 might not work with libiconv.so.3.





Shared object archives are sometimes referred to as dynamically linked libraries as the final 'connection' or link between the binary and the contents of the archive is done as the binary is loaded for execution. Some operating systems also allow the modules from a shared library to reside in one spot in memory and to be shared by any currently running programme that needs the functionality provided. This has the advantage of reducing the total memory needed to support concurrent executing programmes that all reference the same archive(s).








If you are running on a UNIX machine, execute man for ld, ar, and ldd to see more information about creating archives, linking, and determining the reference(s) of a binary to shared objects.

innia

Is there any library function in C++ which could clear the run screen?

if you are talking about plain old c++ programming, I guess the conio.h has a funcition to clear the screen;





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


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





void main()


{


clrscr();





}





i guess this works.

Is there any library function in C++ which could clear the run screen?
What you see below are the nest of functions that you can use on your key board for short cuts. Copy and paste this and save it for future refrence.





Tech Tips on Windows Keyboard Shortcuts for V6.0, and updated with all NEW shortcuts for Internet Explorer v7.0.





Borrowing from Firefox and other browsers, IE7 now features tabbed-browsing. With tabbed-browsing you can, among other things:





Use one Internet Explorer window to view all your web pages.


Open links in a background tab while viewing the page you're on.


Save and open multiple web pages at once by using favorites


and home page tabs.





Most people think they know the ins and outs of using their favorite software (and maybe they do), but there are hundreds of little shortcuts that can be used to make common tasks even easier. This Tech Tip is going to follow a different format than the norm and will list a few dozen of these hot keys that can be used to make working in Microsoft Windows even easier.





The shortcuts covered are broken up into groups based on the main key involved in activating them. So, let’s take a look at what we can do with the ALT, CTRL, SHIFT, and Windows Keys, as well as a few combo moves…





General Keyboard Shortcuts:


CTRL+C (Copy)


CTRL+X (Cut)


CTRL+V (Paste)


CTRL+Z (Undo)


DELETE (Delete)


SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)


CTRL while dragging an item (Copy the selected item)


CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)


F2 key (Rename the selected item)


CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)


CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)


CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)


CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)


CTRL+SHIFT with any of the arrow keys (Highlight a block of text)


SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)


CTRL+A (Select all) F3 key (Search for a file or a folder)


ALT+ENTER (View the properties for the selected item)


ALT+F4 (Close the active item, or quit the active program)


ALT+ENTER (Display the properties of the selected object)


ALT+SPACEBAR (Open the shortcut menu for the active window)


CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously)


ALT+TAB (Switch between the open items)


ALT+ESC (Cycle through items in the order that they had been opened)


F6 key (Cycle through the screen elements in a window or on the desktop)


F4 key (Display the Address bar list in My Computer or Windows Explorer)


SHIFT+F10 (Display the shortcut menu for the selected item)


ALT+SPACEBAR (Display the System menu for the active window)


CTRL+ESC (Display the Start menu)


ALT+Underlined letter in a menu name (Display the corresponding menu)


Underlined letter in a command name on an open menu (Perform the corresponding command)


F10 key (Activate the menu bar in the active program)


RIGHT ARROW (Open the next menu to the right, or open a submenu)


LEFT ARROW (Open the next menu to the left, or close a submenu)


F5 key (Update the active window)


BACKSPACE (View the folder one level up in My Computer or Windows Explorer)


ESC (Cancel the current task)


SHIFT when you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing)








Microsoft Internet Explorer 7.0 Keyboard Shortcuts:


CTRL+click (Open links in a new tab in the background)


CTRL+SHIFT+click (Open links in a new tab in the foreground)


CTRL+T (Open a new tab in the foreground)


ALT+ENTER (Open a new tab from the Address bar)


ALT+ENTER (Open a new tab from the search box)


CTRL+Q (Open Quick Tabs - thumbnail view)


CTRL+TAB/CTRL+SHIFT+TAB (Switch between tabs)


CTRL+n (n can be 1-8) (Switch to a specific tab number)


CTRL+9 (Switch to the last tab)


CTRL+W (Close current tab)


ALT+F4 (Close all tabs)


CTRL+ALT+F4 (Close other tabs)


For more information, visit: http://www.microsoft.com





Dialog Box Keyboard Shortcuts:





If you press SHIFT+F8 in extended selection list boxes, you enable extended selection mode. In this mode, you can use an arrow key to move a cursor without changing the selection. You can press CTRL+SPACEBAR or SHIFT+SPACEBAR to adjust the selection. To cancel extended selection mode, press SHIFT+F8 again. Extended selection mode cancels itself when you move the focus to another control.





CTRL+TAB (Move forward through the tabs)


CTRL+SHIFT+TAB (Move backward through the tabs)


TAB (Move forward through the options)


SHIFT+TAB (Move backward through the options)


ALT+Underlined letter (Perform the corresponding command or select the corresponding option)


ENTER (Perform the command for the active option or button)


SPACEBAR (Select or clear the check box if the active option is a check box)


Arrow keys (Select a button if the active option is a group of option buttons)


F1 key (Display Help)


F4 key (Display the items in the active list)


BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)





Windows Explorer Keyboard Shortcuts:





END (Display the bottom of the active window)


HOME (Display the top of the active window)


NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)


NUM LOCK+Plus sign (+) (Display the contents of the selected folder)


NUM LOCK+Minus sign (-) (Collapse the selected folder)


LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)


RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)





Microsoft Natural Keyboard Shortcuts:





Windows Logo (Display or hide the Start menu)


Windows Logo+BREAK (Display the System Properties dialog box)


Windows Logo+D (Display the desktop)


Windows Logo+M (Minimize all of the windows)


Windows Logo+SHIFT+M (Restore the minimized windows)


Windows Logo+E (Open My Computer)


Windows Logo+F (Search for a file or a folder)


CTRL+Windows Logo+F (Search for computers)


Windows Logo+F1 (Display Windows Help)


Windows Logo+ L (Lock the keyboard)


Windows Logo+R (Open the Run dialog box)


Windows Logo+U (Open Utility Manager)





Accessibility Keyboard Shortcuts:





Right SHIFT for eight seconds (Switch FilterKeys either on or off)


Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)


Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)


SHIFT five times (Switch the StickyKeys either on or off)


NUM LOCK for five seconds (Switch the ToggleKeys either on or off)


Windows Logo +U (Open Utility Manager)





Remote Desktop Connection Navigation:





CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)


ALT+PAGE UP (Switch between programs from left to right)


ALT+PAGE DOWN (Switch between programs from right to left)


ALT+INSERT (Cycle through the programs in most recently used order)


ALT+HOME (Display the Start menu)


CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)


ALT+DELETE (Display the Windows menu)


CTRL+ALT+Minus sign (-) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.)


CTRL+ALT+Plus sign (+) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)





Other Information:





Some keyboard shortcuts may not work if StickyKeys is turned on in Accessibility Options.





Some of the Terminal Services client shortcuts that are similar to the shortcuts in Remote Desktop Sharing are not available when you use Remote Assistance in Windows XP Home Edition.





Final Words:


Windows hot keys are all intended to provide some sort of convenient alternative to common tasks, and whether specific combinations do so is up to the individual to decide. Some are simple time-saving motions, while others are complex maneuvers in finger gymnastics. There are dozens of other common Windows shortcuts (and even more related to specific software titles), and memorizing just a few of the more basic ones may be worth the time-savings they can afford you.





Good luck and we hope this will help you now as well as in the futire.


Where is the West Regional Library in Cary, N.C. and how do I get there?

This is a brand new library that opened on Sept 16 and is somewhere near Highway 55. I tried the townofcary website with no luck so if they have a website, that would be great also.

Where is the West Regional Library in Cary, N.C. and how do I get there?
The webpage for this library branch is here http://www.wakegov.com/locations/library...





It is located at 4000 Louis Stephens Drive, Cary, NC 27519


How to rebuild the library files in c to debug linking errors?

on runnin the program it will ive the error-


linking error:undefined symbol scanf(............)

How to rebuild the library files in c to debug linking errors?
If you do not have scanf(), you are missing


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





in the file.


How can i make a 'library system' using C++ programming ????what can i use data structures or classes???

am a new programming student and i really tried to do this using structures but i failed so plz can anyone help me with that???

How can i make a 'library system' using C++ programming ????what can i use data structures or classes???
I'm not really well acquinted with C++...is the system development restricted to using C++ only, cause if it's not then it would be better to use C# ( C-sharp) instead as it is easier and simpler to use. My advice is to use classes instead so that you can define the relationships between the classes...making programming for the system so much easier! Hope this helps a little:)

gerbera

I moved my itunes to an external hard drive, now when i open itunes, it creates a music library on my c drive

how do i keep this from happening. IN the preferences tab i even moved the music library to my G (my external drive)





when i reopen itunes it empty and I have to reimport


everything which takes forever.





help?

I moved my itunes to an external hard drive, now when i open itunes, it creates a music library on my c drive
When you move where you store your Itunes library, it will import to the new location. I had to delete the first library then change the location. Then import the songs I wanted to Itunes. That reloaded everything on my ipod. There will be a reference file on you C drive still. I also choose the option of Itunes not duplicating the songs on the other drive.





I then backed all my songs to another exterior drive.
Reply:Maybe leave a copy there so it sees it is already there.


Where can i find c code for library management?

Check out this site http://www.wareprise.com/EnterpriseSoftw...


Can anyone helpme with c coding for library management?

Wait up I'm still in a coding........You damn library management geeks never slow down....


What library and function do you need to open have the program open a file for you in c++?

I'm currently learning c++ and I was thinking about creating a program that opens a file for me. What is the command for opening a file in c++ and, if there needs to be a different library please include that too.





Thanks

What library and function do you need to open have the program open a file for you in c++?
Here's a simple example:





#include %26lt;iostream%26gt; // Header for input/output streams


#include %26lt;fstream%26gt; // Header for file access





using namespace std; // Use the standard namespace





void main () {


// Create a file stream


ofstream myfile;


// Open the file


myfile.open ("example.txt");


// Write to the file


myfile %26lt;%26lt; "Writing this to a file.\n";


// Close the file


myfile.close();


}
Reply:Have a look at the following headers:


%26lt;iostream%26gt;


%26lt;fstream%26gt;


%26lt;iomanip%26gt;





You should see that all sorts of methods for reading/writing files are there.





Here's afewexample portions:





ifstream inFile;


inFile.open("myFile.dat", ios::in);





if (inFile.is_open() == 0)





inFile.get( blah blah blah)

rosemary

Program in c++ under the library stdio.h to make an X O game?

stdio.h isn't a C++ library - it's a C header.





You can probably find some source-code on the net if you search for 'tictactoe.c' or 'tictactoe.cpp', which I assume you haven't done yet.


Could someone give me a tutorial on how to write a GUI framework/library in c++?

I Want to write an API like windows.h or GTK. I know this might be hard, but I want to try.

Could someone give me a tutorial on how to write a GUI framework/library in c++?
go to codeproject.com and learn MFC and WTL for gui framework
Reply:It's harder to write the tutorial than it is to write the library.





Most programmers buy a library, rather than write one, especially C++ programmers. After all, if they were into systems programming, they'd be using C, not C++.





And if you need a tutorial in order to do it, you are going to end up with something unusable.





So, I imagine the answer to your question is "no".
Reply:I don't see why you would want to. On Windows, you can use DirectX, GDI, or GDI+ for graphics work. However, if you've created some useful graphics procedures which make use of DirectX, GDI, or GDI+, then you can just make your procedures public and put them into a .dll file.





There's 2 ways you can go. You can write a COM object, or you can just write a .dll file with public procedures. I don't recommend the COM object route because there is more work and you should know that COM objects, OOP, and frameworks produce bloated, slow code.





Creating a .dll file is easy. I don't recommend that you use a framework (Microsoft's MFC or Borland's VCL) for creating a .dll file because your code might require some of the stupid 'support' .dll files that those frameworks use. You don't want to bother having to include those files when you distribute your .dll file.





Here's information on DLL files:


http://msdn2.microsoft.com/en-us/library...


(Remember to set the linker to create a .dll file, not an .exe file.)
Reply:Or else you may contact a C++ expert at websites like http://oktutorial.com/


C++ Query V.V.URGENT: how to set path for graphics library functions in c++??

the actual problem is whenevr i run the programs containg library functions defined in the file graphics.h the program output shows a .BGI error..so can u suggest me any way to solve this error????

C++ Query V.V.URGENT: how to set path for graphics library functions in c++??
In you programm you are using this function in the following way.


initgraph(%26amp;gdriver, %26amp;gmode, "");





but in this function you have give the path of you tc\bgi folder.


I assume this folder is placed on system in "C:\tc\bgi".Please search this bgi folder in TC folder whatever you use(turboc2 etc)


and give the full path in your initgraph function. just like


initgraph(%26amp;gdriver, %26amp;gmode, "C:\\TC\\BGI\\");


Hope this will help.