Take this string for an example, "asdf 9.000 1.232 9.00 23.1 545.3"..Is there a way to replace any of the doubles with another double? Example: Replace the first "9.000" with a "10.0". I am aware that string::replace will do the trick, but how do I make it work for arbitrary cases? By arbitrary I mean that I don't know the size of the string to be replaced, I just want to be able to replace any number with a given number.
This has the effect of removing the dots but keeping the length of the string the same, so old characters are left over at the end. Is there an extra action to do to x to make it the right size or is there a better way of doing it?
I'm working on a problem in which I've to design a program in which the punctuations should be removed from the string. For eg., if input str is: "Hello!!"; the output must be: "Hello".
I'm not sure how to remove a sub-string (if that's the right word!!) from a string. So, I designed a program which print out the punctuations. For eg., if input str is: "Hey!!"; the output would be: ! !
Here it is:
#include <iostream> #include <string> using namespace std; int main (){ cout << "Enter a string" << endl;
[Code] ....
So, I want to know what should be added to this program so that the punctuations can be removed; or should I rewrite another program for that?
I'm trying to go search through my linked list for a passed string and if it matches, remove it...but obviously link everything back together properly. This is what I have so far but when i pass it to my display function, which is properly working, it goes into an endless loop
Why the program continues to prompt me for a vaild number even when the correct number( a gpa) is entered. I'm not sure if the problem lies in the isDouble function or the getDouble?
*/ Determines whether the string holds a valid double. Checks if each character is digit and there is no more than 1 decimal point. */ bool isDouble (const string &str) { int decimal = 0; for (unsigned int i = 0; i < str.size(); ++i){ if ( str[i] == '.'){ decimal++;}
As long as position+length doesn't exceed the end of the file, all is well. However, if it does, weird things start to happen. In particular, the apparent length of the file (that is, the value of "read" after the function has finished) becomes dependent on "length"). I know that "position" is never past the end of the file.
I made this pthread/mutex program that makes deposits and withdrawals of random amounts. I have it working how I wish, however, I cannot figure out how to make it so that the random values are only within certain ranges. For example, let's just say I want all deposits to be random doubles between 50.00 to 100.00 and withdrawals between 25.00 to 50.00, or something similar.
Ok so I have a class that takes integer fractions and I want it to be able to take doubles also depending on what the user inputs. How would I go about this? I was thinking templates ...
I'm trying to validate my input. I require for the user to enter six doubles and if they don't then I want them to re-enter the information. Here is my code:
Code: while (1>0) { printf("Please enter arguments in the order: negative mass, positive mass, initial x-position, initial y-position, initial x-velocity, initial y-velocity: ");
if ( scanf("%lf %lf %lf %lf %lf %lf",&MassMinus,&MassPlus,&Pos[0][0],&Pos[0][1],&Vel[0][0],&Vel[0][1]) != 6) { printf("Not all numbers were assigned!
[Code] .....
At the moment it just waits if you enter less than six numbers and if you enter any more than 6 it just ignores anything after the sixth number (so pretty much does nothing). Also if I entered 1 2 a b 3 4 instead of entering six numbers it would register that as 1 2 0 0 3 4 but I want it to make the user input the numbers again. I'm also aware that "while (1>0)" isn't good programming form but I'm not really sure what to use instead?
I'm supposed to create a program that will find the min/max values of two ints, doubles, and chars, It's not completely done but here's what I have so far.
It's giving me an Error 1 error LNK2019: unresolved external symbol "public: __thiscall MinMax<int>::MinMax<int>(int,int)" (??0?$MinMax@H@@QAE@HH@Z) referenced in function _mainC:UsersDerickDesktopCiss243Week3 Assignment2Week3 Assignment2Main.objWeek3 Assignment2
Header file #ifndef MINMAX_H #define MINMAX_H #include <iostream> using namespace std; template <class T> class MinMax
[Code] ....
I don't know why the site is adding in extra bits of code like /> in certain areas, it's not there when I paste it in and it's not in my code ....
I'm supposed to create a program that stores names and then the final function is supposed to remove a name. But it only removes the first name instead of the inputted name.
the problem with names.erase(names.begin()+i)?
#include <iostream> #include <string>//include for string function #include <vector>//include for vectors
I'm having a problem with removing an item from a queue. At first in the debugger I got SIGTRAP but I don't get it anymore but the problem still exists. When you try to remove an item from the queue the first nothing happens. Here's the code below compile it and you see what I'm talking about.
I have a program that's supposed to read in a file with comma seperated values. This file contains duplicates. The goal is to write a new file that does not contain any of the duplicates. I've successfully written the code to read in a file and create a new, identical file, but I'm failing at deleting the duplicates.
The format of each line in the file is: index,first_name,last_name,address,city,state,zip_code
This code writes the file I want (overlooking the duplicates) if I implement my equality operator as follows:
bool operator ==(const Person &a, const Person &B)/> { return false; //placeholder }
Obviously this doesn't get the job done, since it will never detect a duplicate. The problem is that whenever I try to write any meaningful code, the program writes an empty file. The idea I've been trying to implement is to compare each of the members of Person like this:
bool operator ==(const Person &a, const Person &B)/> { //if two Person objects have equivalent names, they are duplicates return ( (a.first_name == b.first_name) && (a.last_name == b.last_name) ) }
At first I thought the program was working just as before, but then deleting each line of the file as the result of an error in my code. However, I tried troubleshooting the problem by adding in
cout << a.last_name;
to parts of my code so I could see the value in certain places. Whenever I add this line or try to access a member of Person, the program writes a blank file.
I'm working on creating a windows form with a listbox, textbox, and 2 buttons (add,remove). I need a way of removing every string matching the contents of the textbox from the listbox. Here's what I have:
for (int i=0;i<listBox1.Items.Count;i++) { //... listBox1.RemoveAt(i--) }
Seems to work, but I need a way to show a error message once the user clicks 'remove' and no items in the listbox match.
im working on a homework assignment t that should print all pairs of integers that sum to val. I have so far finished except It prints duplicate values (ie (3,1) and(1,3) for values that add to 4) . how can i remove these duplicate pairs of values?
#include <iostream> #include <map> #include <vector> using namespace std; void printPairs( vector<int> numbers, int val){ int i;
I'm trying to remove the title bar from an external app. The reason is I don't want anyone to be able to move it.
But my code below doesn't remove the title bar. Could this be because it's not removable? I read somewhere title bars of external apps may be not removable if the app doesn't allow it.
So, I'm not sure why my code doesn't work - either it's wrong or the app doesn't permit it?
I am having a problem with the output of a file. My function does everything it needs to do with the exception of one line. I have a .dat file with the following:
Code: joe clint james brint howard jimmy alexander * me
When I run the function my output is as such:
Code: file opened word: joe digit: 3 word: clint digit: 5 word: james
[Code] .....
ERROR non alphanumeric digit on line 4!
File closed "Howard" is only six digits in length. Also it seems to skips a line in the output which could be the extra character but I am not sure. What I find very interesting is the other names, (jimmy & alexander) on separate lines do not have that problem.
Here is my function:
Code: #include "main.h" #include "fileCheck.h" int fileCheck(FILE *fp){
int line_count = 0; int ret_val = 0; int digit_count = 0; char file[BUFF];
[Code] .....
How I can correct this? I am aware of sscanf to parse the line but I do not know the format of the file. All I know is the file will be alphanumeric and if there is a non-alphanumeric, I must print out an error with the line it occurred on such as the above output.
While removing duplicate elements from an array, if more than 4 array elements are same then removal does not work. however my logic seems to be alright. i reckon there is a problem with the conditions and assignments in the three for loops that i have used. the program is as follows:
Code: /*c program to remove duplicate elements in an array*/ #include<stdio.h> int main(void) { int array[30],i,j,k,n; printf("
[Code] ....
Take for instance if the input elements are 1,1,1,1,1,2,2,3,5 then after removal of duplicacy the array is 1,1,2,3,5.
I'm trying to create a database/search engine program and I'm having remove duplicate strings from a vector. I'm mostly just trying to make it so that if 2 or more movie have the same title in the database, it will remove the duplicates and just print out one copy of the movie console. I tried using the unique() command, but it doesn't seem to work.