A text contains a set of natural numbers from 1 to 69. Five numbers are randomly
ID: 3722936 • Letter: A
Question
A text contains a set of natural numbers from 1 to 69. Five numbers are randomly selected among them. They are set of 5 natural numbers in fifty rows. The numbers are in Ranum.txt file. Study these numbers carefully. Ensure you understand the basis of difference between the numbers.
You are required to write a c++ program to display the next set of 10 likely natural numbers in a new text file called Ranum1.txt and in the same format. It should start with a message: “The next set of 10 likely numbers are: ” (80marks)
NOTE: The numbers in each row must be distinct. For example, you cannot have two 5’s or three 7’s in the same row.
Also, DO NOT repeat any of the same set of numbers in the given 50 rows as your next 10 likely set of numbers.
Display of correct numbers (40marks)
Comments on your codes (30marks)
Ranum.txt file
28 - 36 - 41 - 51 - 58
3 - 9 - 16 - 56 - 60
1 - 3 - 13 - 15 - 44
1 - 20 - 61 - 64 - 69
9 - 35 - 37 - 50 - 63
2 - 24 - 28 - 51 - 58
25 - 36 - 37 - 55 - 60
19 - 20 - 50 - 55 - 62
28 - 30 - 32 - 36 - 58
24 - 26 - 28 - 59 - 63
8 - 13 - 27 - 53 - 54
35 - 37 - 46 - 51 - 61
17 - 28 - 31 - 32 - 39
23 - 32 - 44 - 48 - 50
4 - 6 - 16 - 30 - 56
12 - 14 - 20 - 21 - 34
12 - 14 - 26 - 48 - 51
3 - 6 - 19 - 26 - 44
27 - 35 - 38 - 57 - 66
18 - 22 - 29 - 54 - 57
14 - 41 - 42 - 45 - 69
30 - 49 - 54 - 66 - 69
32 - 37 - 56 - 66 - 69
1 - 3 - 13 - 19 - 69
10 - 49 - 61 - 63 - 65
22 - 23 - 62 - 63 - 66
8 - 12 - 25 - 41 - 64
8 - 10 - 21 - 23 - 25
24 - 45 - 55 - 56 - 57
39 - 48 - 53 - 67 - 68
17 - 18 - 24 - 25 - 31
17 - 24 - 35 - 57 - 63
6 - 20 - 29 - 57 - 59
8 - 14 - 32 - 58 - 67
6 - 21 - 41 - 52 - 62
19 - 28 - 43 - 67 - 69
7 - 15 - 32 - 38 - 66
6 - 7 - 16 - 23 - 26
17 - 19 - 39 - 43 - 68
9 - 15 - 43 - 60 - 64
20 - 24 - 26 - 35 - 49
12 - 30 - 36 - 47 - 62
11 - 21 - 28 - 33 - 45
1 - 16 - 54 - 63 - 69
1 - 28 - 40 - 45 - 48
7 - 19 - 21 - 42 - 69
5 - 32 - 44 - 53 - 60
50 - 51 - 59 - 61 - 63
9 - 40 - 63 - 64 - 66
1 - 2 - 18 - 23 - 61
28 - 36 - 41 - 51 - 58
3 - 9 - 16 - 56 - 60
1 - 3 - 13 - 15 - 44
1 - 20 - 61 - 64 - 69
9 - 35 - 37 - 50 - 63
2 - 24 - 28 - 51 - 58
25 - 36 - 37 - 55 - 60
19 - 20 - 50 - 55 - 62
28 - 30 - 32 - 36 - 58
24 - 26 - 28 - 59 - 63
8 - 13 - 27 - 53 - 54
35 - 37 - 46 - 51 - 61
17 - 28 - 31 - 32 - 39
23 - 32 - 44 - 48 - 50
4 - 6 - 16 - 30 - 56
12 - 14 - 20 - 21 - 34
12 - 14 - 26 - 48 - 51
3 - 6 - 19 - 26 - 44
27 - 35 - 38 - 57 - 66
18 - 22 - 29 - 54 - 57
14 - 41 - 42 - 45 - 69
30 - 49 - 54 - 66 - 69
32 - 37 - 56 - 66 - 69
1 - 3 - 13 - 19 - 69
10 - 49 - 61 - 63 - 65
22 - 23 - 62 - 63 - 66
8 - 12 - 25 - 41 - 64
8 - 10 - 21 - 23 - 25
24 - 45 - 55 - 56 - 57
39 - 48 - 53 - 67 - 68
17 - 18 - 24 - 25 - 31
17 - 24 - 35 - 57 - 63
6 - 20 - 29 - 57 - 59
8 - 14 - 32 - 58 - 67
6 - 21 - 41 - 52 - 62
19 - 28 - 43 - 67 - 69
7 - 15 - 32 - 38 - 66
6 - 7 - 16 - 23 - 26
17 - 19 - 39 - 43 - 68
9 - 15 - 43 - 60 - 64
20 - 24 - 26 - 35 - 49
12 - 30 - 36 - 47 - 62
11 - 21 - 28 - 33 - 45
1 - 16 - 54 - 63 - 69
1 - 28 - 40 - 45 - 48
7 - 19 - 21 - 42 - 69
5 - 32 - 44 - 53 - 60
50 - 51 - 59 - 61 - 63
9 - 40 - 63 - 64 - 66
1 - 2 - 18 - 23 - 61
Explanation / Answer
Hi.. I have written c++ program to achiheve above.
Main.cpp
#include <iostream>
#include <fstream>
#include<ctime>
using namespace std;
int main()
{
ifstream in("Ranum1.txt");
int *num = new int[250];
int numcount = 0;
if(!in) {
cout << "Cannot open input file. ";
return 1;
}
char str[255];
char str1[2];
in.getline(str, 255); // delim defaults to ' '
while(in) {
int c=0;
if(in){
//cout << str << endl;
for(int i=0;i<sizeof(str);i++){
if(str[i]==''){
num[numcount] = atoi(str1);
numcount++;
for(int k=0;k<3;k++){
str1[k]=' ';
}
c=0;
break;
}else if(str[i]!='-'){
//if(c<3){
if( str[i]!=' '){
str1[c]=str[i];
c++;
}
//}
}else{
//cout << str1 << endl;
num[numcount] = atoi(str1);
numcount++;
for(int k=0;k<3;k++){
str1[k]=' ';
}
c=0;
}
}
}
in.getline(str, 255); // delim defaults to ' '
}
in.close();
int Temp=0;
srand (time(NULL));
cout << "The next set of 10 likely numbers are: ";
int count5 = 0;
int count7 = 0;
for(int i = 0; i<10; i++)
{
Temp = rand()%250;
if(num[Temp]==5){
count5++;
}else if(num[Temp]==7){
count7++;
}
if(count5 >1){
Temp = rand()%250;
}
if(count7 > 1){
Temp = rand()%250;
}
if(i==0){
cout << num[Temp] ;
}else{
cout << " - " << num[Temp] ;
}
}
return 0;
}
Ranum1.txt
28 - 36 - 41 - 51 - 58
3 - 9 - 16 - 56 - 60
1 - 3 - 13 - 15 - 44
1 - 20 - 61 - 64 - 69
9 - 35 - 37 - 50 - 63
2 - 24 - 28 - 51 - 58
25 - 36 - 37 - 55 - 60
19 - 20 - 50 - 55 - 62
28 - 30 - 32 - 36 - 58
24 - 26 - 28 - 59 - 63
8 - 13 - 27 - 53 - 54
35 - 37 - 46 - 51 - 61
17 - 28 - 31 - 32 - 39
23 - 32 - 44 - 48 - 50
4 - 6 - 16 - 30 - 56
12 - 14 - 20 - 21 - 34
12 - 14 - 26 - 48 - 51
3 - 6 - 19 - 26 - 44
27 - 35 - 38 - 57 - 66
18 - 22 - 29 - 54 - 57
14 - 41 - 42 - 45 - 69
30 - 49 - 54 - 66 - 69
32 - 37 - 56 - 66 - 69
1 - 3 - 13 - 19 - 69
10 - 49 - 61 - 63 - 65
22 - 23 - 62 - 63 - 66
8 - 12 - 25 - 41 - 64
8 - 10 - 21 - 23 - 25
24 - 45 - 55 - 56 - 57
39 - 48 - 53 - 67 - 68
17 - 18 - 24 - 25 - 31
17 - 24 - 35 - 57 - 63
6 - 20 - 29 - 57 - 59
8 - 14 - 32 - 58 - 67
6 - 21 - 41 - 52 - 62
19 - 28 - 43 - 67 - 69
7 - 15 - 32 - 38 - 66
6 - 7 - 16 - 23 - 26
17 - 19 - 39 - 43 - 68
9 - 15 - 43 - 60 - 64
20 - 24 - 26 - 35 - 49
12 - 30 - 36 - 47 - 62
11 - 21 - 28 - 33 - 45
1 - 16 - 54 - 63 - 69
1 - 28 - 40 - 45 - 48
7 - 19 - 21 - 42 - 69
5 - 32 - 44 - 53 - 60
50 - 51 - 59 - 61 - 63
9 - 40 - 63 - 64 - 66
1 - 2 - 18 - 23 - 61
Output:
The next set of 10 likely numbers are: 15 - 54 - 57 - 35 - 38 - 57 - 41 - 21 - 34 - 43
Please test it and let me know any issues. Thank you. All the best.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.