C# :: Program For Generating Electronic License Plate / Number Plate
Jun 22, 2014
How do I program c# code for generating electronic (license plate or number plate) randomly by using C# VS2012? The form of the vehicle license plate is like that:
GB LLNN LLL
Where GB = fixed letters
L = letters from (A to Z) randomly, except ( I, O,U and Z)
N = numbers from (0 to 9) randomly,
I am recreating a hangman game. I'm trying to generate a random number to choose which word from my words list to use and I've done it a billion times before just like this. So, here's my code:
#include <iostream> #include <cstdlib> //standard library. #include <ctime> //for random. #include <fstream> //for reading and writing to a file. #include <string> using namespace std; int main() { int num_words; string word[num_words];
[Code] .....
I have the text file "words.txt" info below.
5 dog cat horse pig bird
If I run the program as it is, I get a segmentation fault core dumped error, however, if I take all the stuff that reads in the words from the words.txt file, like so:
#include <iostream> //every program has this. #include <cstdlib> //standard library. #include <ctime> //for random. #include <fstream> //for reading and writing to a file. #include <string>
How to get this code to compile and build. It gives me a really strange error saying:
"1>Project 7 Code.obj : error LNK2019: unresolved external symbol "void __cdecl checkAnswers(char * const,char * const,int,int)" (?checkAnswers@@YAXQAD0HH@Z) referenced in function _main 1>C:UsersHaruha Raharu HarukoDesktopSpring 2015 Class WorkIntro to ProgrammingProject 7Project 7DebugProject 7.exe : fatal error LNK1120: 1 unresolved externals"
Here is the specifics on the assignment:
"Complete Programming Challenge #12 (Driver's License Exam) with file modification
The State Department of Motor Vehicles (DMV) has asked you to write a program that grades the written portion of the driver's license exam, which has 20 multiple choice questions.
Here are the correct answers:
1. B 5. C 9. C 13. D 17. C 2. D 6. A 10. D 14. A 18. B 3. A 7. B 11. B 15. D 19. D 4. A 8. A 12. C 16. C 20. A
Create a TestGrader class. The class will have an answers array of 20 characters, which holds the correct test answers. It will also have a student array of 20 characters to hold the student's answers. It will have three public member functions that enable user programs to interact with the class: setKey, setStudent, and grade. The setkey function receives a 20-character string holding the correct answers and copies this information into the answers array. The setStudent function will read in the student's answers from the file student.txt and will store the answers in a 20-character array named student. The grade method will compare each student answer to the correct answer in the key.
An applicant must correctly answer 15 or more of the 20 questions to pass the exam. After grading the exam, the program should display the following items:
-the number of right answers and the number of wrong answers -a list of the question numbers for all incorrectly answered questions -a message indicating whether the applicant passed or failed the exam"
#include <ctime> #include <iostream> #include <cstdlib> using namespace std; int main() {
[Code] ....
Write a program that keeps generating two random numbers between 1 and 10 and asks the user for the product of the two numbers, e.g.: "What is 4 x 6?". If the user answers correctly, the program responds with "Right!"; otherwise, it displays: Wrong! 4 x 6 = 24.
Generate as many pairs of numbers as specified and get the answers from the user for each. If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer. Continue generating 2 new numbers until at least one is different from last time.
After presenting the number of pairs of numbers specified and getting the answers, display how many the user got right; e.g.: You got 4 of 5 right. Then, ask if he or she wants to play again, like so: "Do you want to play again? [y/n]". If the user answers with 'y' or 'Y', it again reads the number of questions to ask and generates that many pairs of numbers and reads the answers like before. If the answer is n or N, it quits generating numbers. If the answer is anything but y, Y, n or N, it tells the user to enter one of those letters until it is.
When the user decides to quit and has got less than 75% of all the questions right, the program displays the multiplication table (1x1 through 10x10) before terminating.
After displaying the table, randomly generate two numbers between 1 and 10, display their product and first number and ask the user to guess the second as more practice. For example, the program will generate 7 and 9 and will display 63 and 7 and the user must guess the second number (i.e.: 9). Do this 3 times. Do not repeat code. Use a loop to do this 3 times.
Use a nested for loop to display the table; a bunch of cout statements will not be acceptable. You must also use a loop for any part that calls for repetition such as generating 5 pairs of numbers.
The following is a sample interaction between the user and the program:
I have a program that generates random numbers. After the random number is generated, the program asks if you want to generate another random number. However, if you generate another random number, it is always the same as the first random number. How can I fix this?
I want to generate big random numbers in C(not C++ please).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).
I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)
But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.
Is there a better algorithm to create big random numbers in C?
I'm creating a game in C++ and need to generate random numbers. I know about
int main() { srand(time(NULL)); //Initialises randomiser or sum' like that int x=rand%10; //Generates from 0-9 cout<<x; }
Now, I need the best way to generate random numbers. Do I call "srand(time(NULL));" every time I want to randomise? What is the best method to generate a nearly perfect random number?
I may need to call a randomiser more than once a second, so taking second as seed (I believe that's what srand(time(NULL)); does).
But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.
Is there a better algorithm to create quality big random numbers in C?
I generate a series of random numbers in parallel (using OpenMP), but depending on what number of threads I invoke, I get a different result. From that I conclude that I have made an error somewhere!
Here is the MWE, which generates a number between 0..1 and increments a variable if the generated variable is larger than 0.5:
So it will generate numbers again and again as the loop goes on but it always repeat some numbers. My question is, how would you generate numbers without repeating? Somebody told me that i have to use auto increment, but i really have no idea about that.
I'm trying to create a code that generates random numbers and spits out a sum average and lowest and highest number. I am stuck on the sum however and once I get that I think the average will fall into place. Here's what I have.
My problem says: Have the user enter a number from 1-80 then print out a string of random letters(a to z lowercase) of that length.
I have been able to enter the number and output the correct amount of letters but i can't figure out how to get them to be in a random order and not in alphabetical. Here is what I have so far.
#include <iostream> using namespace std; int main() { int i=0; int num; cout<<"How many letters do yu want in your random string?";
Here's the problem. I want to generate an array of objects from classes.
brick[] tile = new brick[5] // originally wanted an array of 500 to play with but I thought I'd start small first
I wanted to make a draw() function in my "level01" class to generate a map (so I wouldn't have to build them in photoshop then manipulate rectangle bounding boxes). I tried several things...
First, I found a thread that worked to get rid of the null value in the array ("not set to reference of an object" error).
After that, within a for loop, I tried to initiate my values...
for (int i=0; i < tile.Length; i++) { tile[i] = new brick(); // calling the object piece[i] = new PictureBox(); // calling the object's container //tile[i].brick1X = 38; // already had a default set to it so I commented this out to see if it made // any difference... it didn't tile[i].brick1Y += 32; // if this worked, it would have drawn a 32x32 tile down the Y axis every 32 // pixels
[Code] ....
In my Form.cs, I declared my first level map as: level01 L01 = new level01();
Under the form's constructor, I instructed it to L01.draw(); so that it would initiate on the game screen.
Needless to say, I get the game screen and the frame, the menu bar I have pops up. But, no tiles.
I even went so far as to get rid of the null values for [i] in the array (using the above for loop but with fewer tasks within the loop) and created a counter that would count up += 1 every time it would make an object.
if (counter < 5) {
And would put in the above tasks inside of the logic loop. I would either get nothing drawn on the screen or it would throw an exception.
I could easily make this using XNA Game Studio in Visual Studio 2010 but I'm using VS2013 and wanted to do a program straight in C# instead of using XNA.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Windows.Forms;
I'm sure this is pretty simple, but any way to do this. Essentially if I have an array with P collumns and V^P rows, how can I fill in all the combinations, that is, essentially, all possible numbers in base V of P digits.
For example, for P=3 and V=2
000 001 010 011 100 101 110 111
Keep in mind that this is an 2 dimensional array, not an array of ints.
For P=4 and V=3.
0000 0001 0002 0010 0011 0012 ....
Having this array generated, the rest of work for what I'm trying to develop is trivial
This is a code I've written that should do the trick, but for some reason it gives this error on compiling:
"main.cpp:65: error: invalid types `double[3][9][double]' for array subscript"
for (int i=0; i<nrolls; ++i){ int number = distribution(generator); cout<<number<<" "<<endl; }
(original code: [URL] ... )
This outputs: 2 3 1 4 3 4 4 3 2 3 and so on... First of all what those numbers mean? I mean do I have to sum them to create timing? For example: 2, (2+3)=5, (5+1)=6, (6+4)=10,..., and so on..
Secondly, my real question is, I need to produce both random arrivals for network packets and the size of packets. I mean, when the packets come and if packets come, what are the size of packets? How can I do that? I need something like that: [URL] ...
I've written some code to randomly generate probabilities:
int Queue::car_per_hr() { srand( time( NULL )); int prob = rand() % + 101; // Probability in percentage from 0 to 100 int cars; //no of cars per hr
[Code] ....
So it checks through the range of possibilities: 0-20%, 21-40% etc. I then have this to implement it:
#include <iostream> #include <ctime> #include "queue.h" using namespace std; int main(){ Queue car_wash; int NO_HOURS;
[Code] .....
For some reason though, everytime I call the car_per_hr() function, the probability just stays the same. It's output is always locked to the same thing it had to begin with?
Here is what I'm trying to accomplish (it is a rather simple program): A classroom of students are to grade a certain number of other exams. The exams should be distributed equally and RANDOMLY, every student should receive the same number of exams, and no student should receive their own exam to grade. The only problem I have is to generate unique random exams for each student. Right now, I have it set to where each exam is distributed the same number of times, every student gets the same number of exams to grade, and no one gets there own. However, I don't have any parameters that prevent one student from getting the same exam multiple time.
Here is an example output:
Student 1 will grade: 4 3 2 5 <- CORRECT OUTPUT (no exam appears more than once) Student 2 will grade: 5 5 5 1 <- exam 5 appears three times Student 3 will grade: 4 2 2 2 <- exam 2 appears three times Student 4 will grade: 3 3 1 1 <- exams 3 and 1 each appear twice Student 5 will grade: 1 3 4 4 <- exam 4 appears twice (each exam appears four times and every student is assigned four exams. no one gets their own)
Here is my code (area of problem is close to the bottom):
#include <stdio.h> #include <stdlib.h> #include <time.h> void create_class (int); int main (void) { srand(time(NULL));
[Code] ....
I tried keeping the exams for each student in the array exam and then checking each one every time I generate a number, but that didn't work.
We had to generate random, unique numbers in the range [1,15]. But running the program for several times showed a bug: It wouldn't always generate a new number for every repeated number. I can't figure out the problem, especially since it works half the time and I can't figure out what's making it work some times and not others.
bool flag1 = true, flag2 = true, flag3 = true; int i, j = 1; int[] A = new int[11]; Random rnd = new Random(); A[0] = rnd.Next(1, 15); Console.WriteLine("1. = " + A[0]);