Starting from:

$25

CSCI1730 - Breakout  - Lab 02 - Solved

Simple Programs

Problem / Exercise
Write C++ programs to perform the following tasks. In many of the program descriptions below, example inputs and outputs are provided.

•    exclusive.cpp: Let the user input an odd number of positive integers, space separated, on a single line (as seen below). Assume that each integer except for one, the exclusive integer, appears an even number of times in the input. Your program should output the exclusive integer.

Enter integers: 2 1 55 3 2 1 4 4 2 2 55

Exclusive: 3

•    primesum.cpp: Let the user input a single integer n where 1 ≤n≤ 100000. Your program should print the sum of the first n prime numbers. In the first example below, the first 5 prime numbers are 2, 3, 5, 7, and 11.

Enter integer: 5

Prime sum: 28

Enter integer: 100000

Prime sum: 62260698721

•    endtime.cpp: Write a program to read two integers with the following significance. The first integer value represents a time of day on a 24 hour clock, so that 1245 represents quarter to one mid-day, for example. The second integer represents a time duration in a similar way, so that 345 represents three hours and 45 minutes. This duration is to be added to the first time, and the result printed out in the same notation, in this case 1630 which is the time 3 hours and 45 minutes after 12:45. Another example is given below.

Enter in a start time: 1415 Enter in a duration: 50 End time is: 1505

Textbook & Other Resources
Students may find the following sections of the textbook useful for this assignment:

•    DEITEL 2.1–2.8

•    DEITEL 4.1–4.15

•    DEITEL 5.1–5.14

Students may also find the following resources useful for this assignment:

•    std::cout – http://en.cppreference.com/w/cpp/io/cout

•    std::cin – http://en.cppreference.com/w/cpp/io/cin

•    std::getline – http://en.cppreference.com/w/cpp/string/basic_string/getline • std::stringstream – http://en.cppreference.com/w/cpp/io/basic_stringstream

1

1           Some Nonfunctional Requirements
Your submission needs to satisfy the following nonfunctional requirements:

•    Directory Setup: Make sure that all of your files are in a directory called LastName-FirstName-lab02, where LastName and FirstName are replaced with your actual last name and first name, respectively.

•    Documentation: All classes, structs, and functions must be documented using Javadoc (or Doxygen) style comments. Use inline documentation, as needed, to explain ambiguous or tricky parts of your code.

•    Makefile: You need to include a Makefile. The expectation is that the grader should be able to type make clean and make to clean and compile/link your submission, respectively. The resulting executables must correspond to the source code filenames. For example, exclusive.cpp should result in an executable called exclusive. The expectation is that after your program is compiled and linked, the grader should be able to run each of your programs by typing something similar to the following:

$ ./exclusive

•    Standards & Flags: Make sure that when you compile, you pass the following options to g++:

-Wall -pedantic-errors

Other compiler/linker options may be needed in addition to the ones mentioned above.


More products