0% found this document useful (0 votes)
107 views

C++ Burlingame Robotics Programming Training 1

This PDF contains practice projects to get programming team members ready for programming C++ for FRC.

Uploaded by

fsxfreak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

C++ Burlingame Robotics Programming Training 1

This PDF contains practice projects to get programming team members ready for programming C++ for FRC.

Uploaded by

fsxfreak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Iron Panthers Programming Training

Do keep in mind that the internet is available for you to search. Dont search for the solutions to
the problems, search for the individual pieces that form the solution, i.e. how to use a conditional
within a for loop, not how to nd primes from 1-100. Youll be wasting your time if you nd
complete solutions.

Primes from 1100

Write a program that prints all prime numbers from 1100.


Youll need to know how to use:
for loops
for (int i = 1; i <= 100; i++) { }
depending on your method of prime identication:
conditionals
if (true) { //do something }
modulus operator
1 % 3 == 1; 2 % 3 == 2; 3 % 3 == 0;
for loop within a for loop
for (...) { for (int j = 1; j <= 100; j++) { } }
arrays/vectors
int primes[100]; std::vector<int> primes2;
I recommend using the Sieve of Eratosthenes. This involves iterating through an array
of booleans, and marking multiples of numbers as composite numbers by setting
them to false. This method will use a for loop within a for loop, conditionals, and a
vector.

Outputting primes from 11,000,000 to a text file

Write a program that generates a vector of all the primes from 11,000,000, and outputs them to a .txt le, one per line.
Youll need to know how to use:
everything from above
std::ofstream textFile("muhprimes.txt");
ofstream (part of fstream)
textFile << "2 3 5 7 9 11 13\n";
escaped characters (\n)
Notice how outputting to a text le looks strangely similar to outputting to the
terminal. Perhaps there is a reason why the angle brackets point towards textFile and
cout.
You may run into trouble with the size of integers, and your program may take more
than one second to execute. Nothing that cant be solved with the Sieve of Eratosthenes, no doubt.

Name-replacer

Write a program that parses a le that contains an excerpt from your favorite book,
and replace every instance of the main characters name with your name.
Youll need to know how to:
parse command line args (int argc, char *argv[])
input from a le and output to a le (std::ifstream, std::ofstream)
parse strings (std::string)
1

continued.

You might also like