C++ :: Program To Extract Special Code From A List Of Numbers
Nov 1, 2013
I am a beginner and I ALWAYS have the toughest time doing I/O files. It's extremely frustrating. It "seems" it should be so simple. The program should find a code from a list of numbers. These numbers are from 0 - 9, and after each number is a space in the file. Your job is to extract a special code containing only 10 of those numbers. For the number to be part of the code, it should be divisible by 2. After extracting 10 numbers divisible by 2 for the code, write those 10 numbers to the file to form the expected code.
Input file is ("question.txt")
Output should be ("code.txt")
Should this contain a "for loop" or If/else ?
Here's what I did . .
/
// int numbers, total, counter;
ifstream inFile;
inFile.open ("question.txt");
outFile.open ("code.txt");
if (!inFile)
[Code] ....
View 2 Replies
ADVERTISEMENT
Mar 14, 2013
How to write a C or C++ program that extracts certain numbers out of a section after the 4, 5 and 6 space.
For Example:
The output file will produce:
[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.274000 0.010000 54 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 18];...
So I want to extract the numbers 0.650000, 0.006000, 0.020000 because those are the 4,5,6 space after [ [
Another problem I have is that the output file I showed will always being updated constantly for instance as follow:
[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.2054000 0.010000 10 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 13];...
[ [1900 00 0 -1.000000 0.650000 0.006000 0.020000 2.694000 0.010000 9 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10];...
[ [1900 00 0 -2.000000 0.6023000 0.04000 0.050000 2.2454000 0.010000 5 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 12];...
And it will keep updating like this and I want to update the previous numbers I extracted with now the new numbers after the 4,5, and 6 space.
So I have to write a code to let it know when it encounters [ [ start looking for the 4,5,6 space and get those numbers and once it reaches ;... that's the end of that section so re-look for the next section of numbers after the 4,5,6 space.
The file will be a text file or matlab file that is always being updated with these sections of numbers. Can I make this a #include<nameoffile.h> or does .h not work with a file that is always being updated.
View 2 Replies
View Related
May 23, 2013
My code is currently reads in a string of lower case letters, identifying the occurrence of each letter.
Code:
#include <stdio.h>
#include <string.h>
int main()
{
[Code]....
My issue is that I want my code to read uppercase and special symbols. showing the occurrence of both.
Code:
else if(str[x] >= 'a' && str[x] <= 'z');
else if(str[x] >= '0' && str[x] <= '9');
However I struggle to implement it
View 3 Replies
View Related
Sep 18, 2014
I'm searching a program that can detect a special type of memory leaks, like these:
int a = 12;
char c[10];
char cc = c[a];
View 8 Replies
View Related
Jul 1, 2014
I am trying to write a function that extracts chunks of numbers from a stream (ie if i had "ui33ui24ui23hjdwejf" it would extract the chunk 33), and its finished, but it wont compile. errors here: [URL] ...... its only one line in an include file, but im stumped. anyways, this is the most updated version of the code: [URL] .....
View 1 Replies
View Related
Oct 30, 2014
while(!secList.empty()){
Security se = Security();
se = secList.extract(); // CRASH
cout << "Security info: " << se.security << endl;
cout << "Transaction List: " << endl;
while(!se.tranList.empty()){
Transaction tr = Transaction();
[code]....
my program crash when it try to assign the return value of the function to the local value. extract function does return correct value, but it just crash when done executing.
View 4 Replies
View Related
Mar 25, 2013
I am a database developer and I am assigned with a task to finish it as someone left it in the middle.The number 1406357289 ,is a o to 9 pandigital number because it is made up of each of the digits of 0 to 9 in some order,using each digit only once, but it also has a rather interesting sub-string divisibility property. Let d1 be the 1st digit,d2 be the 2nd digit, and so on.In this way,we not the following;
d2d3d4=406 is divisible by 2
d3d4d5=063 is divisible by 3
d4d5d6=635 is divisible by 5
d5d6d7=357 is divisible by 7
d6d7d8=572 is divisible by 11
d7d8d9=728 is divisible by 13
d3d4d5=289 is divisible by 17.
Find the sum of all 0 to 9 pandigital numbers with this property.
View 5 Replies
View Related
Feb 27, 2014
When I run this in main it gives me a windows error message. I believe it has something to do with my insertAtEnd function but I've gone over it a million times....
#include<iostream>
#include<string>
#include<vector>
#include"RhymeGame.h"
using namespace std;
Game::Game() {
head = NULL;
[Code] ....
View 3 Replies
View Related
Aug 8, 2013
I am currently trying to write a code that will store PID numbers of a child after a fork, I have to be able to enter an amount that will be created, so far I have managed to be able to get them to print (which puts me on the right path as far as I am concerned) but I am having issues. Using the following code:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
[Code].....
View 3 Replies
View Related
Nov 5, 2014
This program gets input from a file and output to the screen and to a file. The difficulty I am having is summing the number I retrieve from the file for the individual numbers of sightings.
#include <fstream> // enables us to read and write files
#include <iostream> // for cin and cout
#include <cstdlib>
#include <string> // enables us to hold strings of characters
#include <cctype>
using namespace std;
[code].....
View 14 Replies
View Related
Aug 17, 2014
I am wondering if there is some repository of c++ code for statistics comparing two columns of numbers? Statistics are so common now that it seems like with the oo concept of reusable code there should be allot of that floating around. Code that would accept two vectors and generate comparisons like pearson's correlation, root mean square error, mean absolute error, median absolute error, etc would be very useful.
I have looked around some and find some code examples, and other posts basically saying, "Google the algorithm and figure it out yourself." At this point, there should almost be stl classes like the ones for union(), intersection(), accumulate(), and other simpler math functions.
View 3 Replies
View Related
Apr 18, 2013
I have been working on the same problem as mp252 from an earlier thread and 4 days later, I appear to have it working. Mine only goes from 0-9999 though as I must move on!
Code:
#include <iostream>
#include <string>
int getThousands(int number);
int getHundreds(int number);
int getTens(int number);
int getUnits(int number);
void printNumber(int number);
[Code]......
I had a scrap of paper like a mad scientist trying to find relationships between numbers and the values that they would return through my functions. This is how I arrived at the conditions of my if statements in 'void printNumber'.
I have seen other code that allows a greater range but I can't quite follow it (yet):
C++ code by fun2code - 67 lines - codepad
View 1 Replies
View Related
Apr 9, 2014
I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.
Code:
#include <stdio.h>
int is_prime( int num );
int get_positive_integer(void);
int main( ) {
int upper; /* upper limit to check */
int num; /* current number to check */
int isprime;
/* used to flag if number is prime or not */
[Code]...
It says the error is on line 23
View 6 Replies
View Related
Apr 10, 2014
I'm trying to put in my messages, in my program, some special chars but when i try something like the following code, i get the output below.
#include <stdio.h>
int main( ) {
printf("Trying this char: %c", 160);
printf("Trying this char: %c", 163);
return 0;
}
Output:
Trying this char: �
Trying this char: �
How can i put those special chars? I would like to use: é, ú, ç, à, Ú, À, ...
View 14 Replies
View Related
Jan 30, 2012
For example, how to output "Delta" (like a triangle) in C++?
View 13 Replies
View Related
May 13, 2014
im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.
void OlympicJudging() // Olympic Judging {
int numbers [6];
double average, sum = 0;
int temp;
for(int i = 0; i < 6; i++){
cout << "Please type a value for scores: ";
cin >> numbers[i];
[Code]...
View 5 Replies
View Related
Apr 30, 2014
There are many libraries in C++, but how are they made?
For example: SDL, SFML, Open CV, STK
There are no special functions in C++ from which we can create such libraries, If I wanted to create a library that processes sound signals, how would I do that? How can I access the mic, speakers and process the signals.
Open CV processes videos but which functions does it use?
View 3 Replies
View Related
May 24, 2013
I have an array in a class with some numbers in a specific order. Now I want to create a set with references to that array ordered after the arrays content. I thought a solution could be something like
class Holder {
int o[10]= {1,5,7,2,3,8,4,9,6,0};
public:
set<int,my_order> m_s;
Holder() {
for(int i=0; i<10;i++) {
m_s.insert(i);
[Code] ....
How to create the my_order.
View 9 Replies
View Related
Feb 6, 2015
I have to make an email validation program and i am halfway done. I only have one more problem, consider the ff. example:
Enter email:
myemail.@something.com //this is the input
Invalid //this should be the output
How can i determine if there is a special character near the '@' sign? and vice versa?
View 4 Replies
View Related
May 15, 2014
how to rearrange lists in an special manner.
I have heard about the hashset but I do not fully understand how that thing works or if it is the best option for this issue.
Basically I have 3 lists: LIST1, LIST2 and LIST3.
LIST1 is a set of xyz points and LIST2 shows how the points are connected (clockwise, counter clockwise, coolinear).
For example the fact that in the first line of LIST2 appears 0, 1, 2,-1 means that the points in LIST1 are connected as follows:
(0 0 128.588459085565)->(25 0 134.979628462965)->(0 0 134.979628462965)
Same for line2 of LIST2: 1, 4, 2,-1
(25 0 134.979628462965)->(25 0 140.100717207301)->(0 0 134.979628462965)
etc...
The value -1 at the end of each line does not mean anything but I need to keep it.
Finally LIST3 tells me if the points are connected counterclockwise (-1), clockwise (1), or coolinear (0).
The thing is that I want to get things as follows:
If the values of list 3=1 then I need to extract all the points in the list 1 that correspond to the value 1 in order. However the values in LIST2 cannot keep being 1, 4, 2,-1 they need to be reorganised starting by zero. Expected result in LIST2= 0,3,1,-1.
We need to do this for each value in list3 (1,-1 and 0).
The idea is to get 3 groups of values:
- Group 1 including all the values that are clockwise (list3) with the points in order in list1 and showing connections starting from zero on in list2.
- Group 2 including all the values that are counterclockwise (list3) with the points in order in list1 and showing connections starting from zero on in list2.
- Group 3 including all the values that are coolinear (list3) with the points in order in list1 and showing connections starting from zero on in list2.
The idea is to be able to print 3 files in the following way:
FILE1:
Points which are clockwise in LIST 1
...
Connections of those points in LIST 2
...
FILE2:
Points which are counterclockwise in LIST 1
[code]....
View 5 Replies
View Related
Feb 22, 2012
Code:
Exercise. 1.5 A number is special if it is divisible (no remainder) by 15. A number is big if it is greater than 999. A number is weird if it is divisible by 5 and 6 but not 18. A number is scary if it is big or weird.
Write a program to check which of the following, 450, 540, 600, and 675 are special but not scary.
Declare four variables called special, big, weird, and scary and make suitable assignments to these variables as a number is tested.
I want to do it with a function, but it just output that everything is Special and Scary, and that everything values 4199536.
Code:
#include <stdio.h>
#include <stdlib.h>
/* Function */
int test(int);
int test(int a) {
int sc, sp;
[Code] .....
View 5 Replies
View Related
Jun 1, 2013
Let assume that there is an array of integer numbers in the range from 1 to N that are located in the ascending order. For example
#include <iostream>
#include <numeric>
#include <iterator>
int main() {
const size_t N = 20;
[Code] .....
How can it be converted using some one standard algorithm such a way that the resulted sequence would look like
1 3 5 7 9 11 13 15 17 19 20 18 16 14 12 10 8 6 4 2
View 19 Replies
View Related
Nov 28, 2012
I have a file that contain different content, some lines inside that file looks like that :
Time : xx:xx:xx
Time : xx:xx:xx
So, I want to grab lines that start with "Time : " and put them inside a list<string> for later use. I am using windows so I don't know if the newline character is '
' or '
' also I don't want my grabed line contain any special character.
I have this code, but didn't work well because some special characters remain inside the string.
Code:
string buf;
list<string> ls;
ifstream read("test.txt", ios_base::binary);
while(!read.eof())
{
getline(read,buf,'
[Code]...
View 1 Replies
View Related
Mar 24, 2014
In my app the user can select the pages to print by typing in a start and an end page. I think this is the standard dialog.
How can I give the user the possibility to select e.g. page "1,2,6-9" like in Word?
View 4 Replies
View Related
Mar 5, 2013
How can I pass ":" or " " as an argument to a process?
I start a process which takes an IP and port number (ex 222.240.224.131:80) as argument. Another character that I want to pass is white space character. Both of these characters cuts the argument string and sends only the part that leads them.
View 1 Replies
View Related
May 20, 2014
I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.
#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!
[Code]...
View 5 Replies
View Related