Creates a string concat primes of given length

Assignment Help C/C++ Programming
Reference no: EM131373871

Write a C++ program which:

1. takes an integer n ≥ 0 from stdin provided by the user.

2. creates a string concat primes of length 1000 from the first k prime numbers by concatenating them as strings. (You have to decide on the value of k).

3. The program has to compile and work perfectly in visual studio or xcode (mac)

4. prints the first 5 characters of concat primes starting at index n.

For example, the first k prime numbers are 2, 3, 5, 7, 11, 13, 17.... Thus, concat primes = "2357111317...". If the user provides n = 3, the program should print 71113.

A sample of expected output for various values of n is given below:
n Output
0 = 23571
3 = 71113
6 = 13171
10 = 19232
120 = 92332
998 = 91

Using this format
#include<iostream>
#include<string>

std::string get_concatenated_primes()
{
return "2357111317";
}

std::string get_slice_of_5(const std::string & primes, const int index)
{
return "23571";
}

int main()
{
int n;

while(std::cin >> n)
{
std::string concat_primes = get_concatenated_primes();
std::cout << get_slice_of_5(concat_primes, n) << std::endl;
}

return 0;
}

Reference no: EM131373871

Questions Cloud

Environments of service and manufacturing organizations : On what dimensions of external dependence do the environments of service and manufacturing organizations differ? Does this have implications for how these two types of organizations might manage their environmental interactions?
Who developed the leed rating system : Why is it important to meet the building standards during new construction rather than waiting until some later time to incorporate them?
Which of the following is an intangible asset : Which of the following is an intangible asset - If an owner invests her laptop computer and printer in the business, there is an increase
Refinement of a random process : What are your thoughts concerning the probability that programmed development resulted from refinement of a random process?
Creates a string concat primes of given length : creates a string concat primes of length 1000 from the first k prime numbers by concatenating them as strings. (You have to decide on the value of k).
Why is the role of the boundary spanner so important : 2. Why is the role of the boundary spanner so important? so difficult? How could an organization prepare one of its employees for this role?
Phenotype seen in the mutant fly : The convention for naming genes is to name them after the phenotype seen in the mutant fly. Based on this convention, which of the following is the best choice for naming the gene involved in fly eye color that was identified in this study of flie..
Respond to the presidents memorandum : Assume that you are the vice president, and respond to the president's memorandum. Consider as many aspects of the environment as you can apply to this situation.
Develop a mandatory green building standards code : What makes a building sustainable? From a financial perspective, should owners of a sustainably managed building expect a higher return on investment?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program to convert string in reverse case

Write a program that asks the user for a string and display that same string in reverse order on the screen. The function should take a string parameter with the users input and return the same string, except each character is in reverse order

  Associate the variable contains

Given the string, s , and the list, lst , associate the variable contains with True if every string in lst appears in s(and False otherwise). Thus, given the string Hello world and the list ["H", "wor", "o w"] , contains would be associated with True..

  Write a c++ program to calculate the sum

The list of all natural numbers less than 10 that are multiples of 3 or 5 is 3,5,6,9. The sum of these multiples is 23. Write a C++ program to calculate the sum of all such multiples less than 1,000.

  How would you put a empty space between output

How would you put a empty space between output, right now it prints 6 rows but how do i add a space or a "\n" for example row1 row2 row3

  What is the difference between protected and private members

What is the difference between protected and private members? How do the default constructors and destructors behave in an inheritance hierarchy? What is a virtual member function?

  Write a c program to search a list of integers

Write a C program to search a list of integers for a particular value. The user should be prompted to enter the value to be searched for. Your program will then print out whether the value was found or not.

  C program to randomly generate more than ten ip address

Write C or C++ program which Randomly generates more than 10 IP addresses written in decimal format and write results in text file (e.g. Dec_IPAddresses.txt)

  Create a derived class to store the age of the patients

Create a structure to store the date (year, month and date as its members). Create a base class to store the above information. The member function should include functions to enter information and display a list of all the patients in the database. ..

  Write program that reads positive integer using spim system

Write and test a program that reads in a positive integer using the SPIM system calls. If the integer is not positive, the program should terminate with the message "Invalid Entry"; otherwise the program should print out the names of the digits of..

  Determine how long the match goes on

Determine how long the match goes on (it might be just N bytes long, or it might extend past the first N matching bytes to be many bytes longer).

  Uml diagram of all the classes

Speaking of converting into the correct object-type, the goal of the factory is to abstract away object creation.

  Standard deviation of the resistance distribution

The distribution of resistance for resistors of a certain type is known to be normal, with 10% of all resistors having a resistance exceeding 10.634 ohms, and 5% having a resistance smaller than 9.7565 ohms. What are the mean value and standard d..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd