C++ :: Changing State Names To Abbreviations?

Feb 13, 2014

The purpose of the code is to read in state names, say california and print CA. However, if it was a state with two words, it would read in only the first letter of each. I.E New Hampshire would be NH.

here's my code:
#include <iostream>
#include <iomanip>
#include <cctype>

[Code].....

I am able to get the one word states and tried getting the two word states but it doesnt work.

View 1 Replies


ADVERTISEMENT

Visual C++ :: Reading And Outputting Files - Sentences And Abbreviations

Mar 26, 2013

I have got an assignment. It is about comparing two files one file has sentences and the other abbreviations. so far i have managed to compare the abbreviations which appear in the sentence and erase punctuation linked to abbreviations.

However I am currently stuck on putting the punctuation back in when outputting the file. I am also stuck with replacing matching words in the sentences with the expanded abbreviations. Not sure which code to show. but sentences and abbreviations are below.

ABBREVIATIONS

Aberd Aberdeen
admin administration
approx approximate
Austral Australia
div division
Capt Captain
Comdr Commander
e east
HQ Head Quarters
m metres
mil million
mt Mount
n north
NATO North Atlantic Treaty Organisation
NSW New South Wales
pop population
s south
sq square
w west

Text file

NATO troops were on exercise in Aberd Capt Jones of the first div told Comdr Frank that his troops were near the E flank of the NATO forces. Complaining about the amount of Admin, Capt Jones radioed the NATO HQ asked for navigation relative to the HQ. The Captain then left.

For example the abbreviation "Aberd" in the sentence above needs to be replaced with Aberdeen from the abbreviations file. I need the last part of the abbreviation not "Aberd Aberdeen" need just "Aberdeen". Hope the info is understandable.

View 6 Replies View Related

C++ :: Delete Specified Names From A List Of Store Names?

Feb 10, 2013

i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.

void Store::deleteSpecifiedStoreFromList(string choice) {
for (int i = 0; i < this->stores.size(); i++) {
if(this->stores[i].getStoreNames() == choice) {
this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() );
}
}
}

View 4 Replies View Related

C++ :: Empty State Of Queue?

Feb 18, 2013

what is the empty state of queue?

View 5 Replies View Related

C/C++ :: Linux Console Get Key State

Jan 23, 2014

I want to create command line game in Linux but I don't know to get the key state. I heard of getch() but that stops the program.

View 1 Replies View Related

C++ :: State Of Variable In One Expression

Mar 27, 2014

I thought that an operator performs a permanent change in a local variable. For example, if x is 00000000 00000000 00000000 00000011 (a 32 bit unsigned integer that resolves to value of 3) and p is 2, in the expression "return (x >> p) | (x << (s - p))", the right shift would permanently change x to 0 and the time we evaluate x again in "(x << (s - p))", x will already be 0. If that's the case, then this function doesn't make sense. This function makes it seem like that the >> and << operators do not change the value of x. It makes it seem like first we right shift x to 0 and then left shift by 20 bits to make x 11000000 00000000 00000000 00000000. If that's the case, then the function does exactly what it is supposed to do (rotate the bits). So which is it?

unsigned int rightrot(unsigned int x, unsigned int n) {
size_t s = sizeof(x) * CHAR_BIT;
size_t p;
if(n < s)
p = n;

[Code] ....

View 2 Replies View Related

C++ :: Making A Finite State Machine For Lab?

Apr 20, 2013

I am making a finite state machine for a lab. I have here a 2 files with the code for the FSM. I know it isn't finished yet, I know what needs to be put in. The only things I would need help on are the errors that I get.

Warrior.h
#ifndef _WARRIOR_
#define _WARRIOR_
#include "State.h"

[Code]....

View 1 Replies View Related

C/C++ :: Reverse A String And State If It Is A Palindrome

Mar 28, 2015

I am supposed to take the three string lines from a text file and then individually reverse them and state whether or not they are a palindrome. I have the three lines from the text file into string variables already but I am not sure on how to reverse them and then see if they are the same reversed(palindrome)

Here is my code so far -->

#include <iostream>
#include <string>
#include <cctype>

[Code].....

EDIT: Ignore line 123 and down in the code. That was merely test code and will not be used.

View 7 Replies View Related

C++ :: State The Values Of Each Int Variables After Calculation Is Performed

May 2, 2013

Question: State the values of each of these int variables after the calculation is performed. Assumed that, when each statement begins executing, all variables have the integer value 5.

a) product *= x++;

b) quotient /= ++x;

What is the answer for a and b?

View 4 Replies View Related

Visual C++ :: Debugging - Revisiting Same Memory State?

Oct 31, 2013

When running my code in Visual Studio, there is a particular point in the code where my program is crashing. To debug this, I am adding a break point in Debug mode just before that point, and observing what happens as I step through the code. However, to get to this break point in the code takes about a minute of running the program. So I'm wondering if there is a tool in Visual Studio to reload the state of a program's memory from a previous run, so that I can immediately get to the break point without having to wait for a minute each time?

View 6 Replies View Related

C++ ::  Initializing Boost Asio Variables In State Program

May 5, 2014

I am trying to initialize this chunk of code without it starting at the main menu in my state program:

boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(argv[1], argv[2]);
tcp::resolver::iterator iterator = resolver.resolve(query);
chat_client c(io_service, iterator);
boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));
char line[chat_message::max_body_length + 1];

This code came from a example at the boost example list: URL.....I want the networking to start when the multiplayer state initializes. This is how my program basically looks like:

//Main.cpp
main() {
if (!quit) {
while( handleing_events ) {
CurrentState->handleEvents();

[code].....

I tried to put the stuff in extern at states.h, and initialize it at Multiplayer(), but in handleEvents & ~Multiplayer, it says "c" is not defined...

View 8 Replies View Related

C++ :: State Design Pattern - Calling A Class Member

Oct 17, 2013

In the following code example of the State Design Pattern, in the main code at the bottom it defines an instance of class Machine, and then calls Machine::off;. Why doesn't it instead call fsm.off;?

Machine fsm;

Machine::off;

Then I tried imitating that by adding a class Abba, and then doing:

Abba a;
Abba::DoStuff();

but that didn't work. Why?

Full code example:

// StatePattern.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;
class Machine {
class State *current;

[Code] ....

View 3 Replies View Related

C/C++ :: Circular Buffer In The Form Of Finite State Machine

Dec 11, 2014

I'm supposed to create a circular buffer that reads an input file and outputs data after running though basically an integral equation. Everything my be referenced by pointers. When I build I am being told segmentation fault: 11. From what I have gathered that means there is a problem with my memory allocation correct? I'm including the custom header file and the main.c as well.

header file :

#ifndef FSM_H
#defineFSM_H
#define INPUT_BUFFER_LENGTH 2
#define OUTPUT_BUFFER_LENGTH 2
#define INITIAL_INPUT {0,0}
#define INITIAL_OUTPUT {0,0}

[Code] .....

View 1 Replies View Related

C++ :: Concatenation Of Strings When Entering City / State And Zip Code

Apr 15, 2013

I have written my code, but can't seem to figure out why it doesn't enter the while loop and start asking for Input.

Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
//declare variables
string cityName = "";
string stateName = "";

[Code] ....

View 3 Replies View Related

C :: Program To State User Chinese Zodiac And Horoscope Sign After Inputting Birthday

Mar 26, 2013

I am a beginner trying to write a program that would state a user's chinese zodiac and horoscope sign after inputing his or her birthday. I have been, however, having trouble getting the program to run correctly.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define CAPRICORN "G"
#define AQUARIUS "W"
#define PISCES "F"

[Code] ......

View 3 Replies View Related

Visual C++ :: Puzzle Game - Implement A Way To Save Board State Throughout User Inputted Path

Mar 16, 2013

I've been trying to figure out how to implement a way to save this board state throughout a user's inputted path. At the end, I need the output to print out the board states (user's path) of how he or she got the puzzle solved. This puzzle is the 15 Puzzle; but we have it to change by the user's input on what size they want to play (3x3 to 5x5). How to save the board state of each user input, then print those out in order from beginning to solved puzzle state. Subsequently, I would also need transferring the board state to change with using a vector to store the size based on user input. How to proceed, using a first search to solve the puzzle from the current board's state.

calculations.h

Code:
/*Calculations set as a header to keep compiling simple and faster*/

#ifndef calculations
#define calculations
int solved[5][5];
void initialize(int board[][5], int);
void slide(int board[][5],int move,int);
bool isBoardSolved(int board[][5],int);

[Code] .....

View 6 Replies View Related

C++ :: Changing The Value Of A String?

Dec 17, 2013

If I was to input for example 'x' into my program, how could I change that to something like 'HuS581' every time that specific character was inputted?

View 2 Replies View Related

C :: Changing The Value Of Something From A Function

Oct 30, 2013

I was talking to someone earlier about how to change the value of something from a function, and they said what was needed was to use a ** to change something, and was wondering if I could get a walk - through of what happens. I understand a single pointer well enough, but a pointer through a pointer is kind of confusing to me. Here is a simple example.

Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int add(int ** TOP, int * stack);

int *stack = NULL;

[Code] ....

Why is it that when the program prints the address of TOP in main, it is different than the address of TOP in the function? Is it because it is a different instance of TOP because it is in the function? When I put the number on *TOP, and come out of the function back to main, it then says the address of TOP is the number entered into *TOP, and am not sure why. And the **TOP ++ at the end I am thinking it increments malloc by 1, therefore bringing the pointer TOP up to point at the next element, or am I completely off base there?

View 7 Replies View Related

C++ :: Changing Const Int Value?

Nov 7, 2013

#include <iostream>
#include <iomanip>
using namespace std;

// cin.get() <-------------- used to let the user read the screen

// Function prototypes
void calcSales(const int [], const double [], double [], int);
void showOrder(const double [], const int [], int);

[Code] ....

How can i change the "const int NUM_PRODS = 12;" from saying id 1, id 2, id 3, etc. to custom product numbers?

View 1 Replies View Related

C++ :: Changing Some Bit Of A Number

Jan 1, 2015

I use miracle library to work with big numbers. I defined a number for example X with 192 bit. at first X= 0 ;I want to change for example 3 bit of it to 1 randomly.as a example:

assume that X has 10 bit :
X=0000000000
random numbers should be :
1000010001
1010100000
1100000100

View 1 Replies View Related

C/C++ :: Changing Complexity From O(n) To O(1)

May 5, 2012

For the following code :

 s = 0 ;
 for(i=m ; i<=(2*n-1) ; i+=m) {
            if(i<=n+1)
            { s+=(i-1)/2 ; }
           else
            { s+=(2*n-i+1)/2 ; }  
      }  

I want to change the complexity of the code from O(n) to O(1) . So I wanted to eliminate the for loop . But as the sum "s" stores values like (i-1)/2 or (2*n-i+1)/2 so eliminating the loop involves tedious calculation of floor value of each (i-1)/2 or (2*n-i+1)/2 . It became very difficult for me to do so as I might have derived the wrong formula in sums of floors . Need Changing complexity from O(n) to O(1). Is there any other way to reduce the complexity ? If yes ... then how ?

View 3 Replies View Related

C++ :: Changing From BigInteger To GMP?

May 15, 2012

I have this code which previously used the BigInteger library, however now I have GMP installed and I want to use that instead.

I have read the manual but I cannot figure out how to use GMP in this function without getting errors.

Here is the function:

Code:
int lucas(long p){ //p is a number in the range of 2 up to 50,000,000, possibly bigger
int s = 4; //previously assigned as a big integer
int z; //used in the for loop below
int M = 2; //previously assigned as a big integer
for(z = 1; z < p; z++){ //this accomplishes the same as 2 to the power of p, and is stored in M
M *= 2;
}
M--;

[code]....

I can initialize variables using the gmp library, but when I'm trying to use the mpz_pow_ui() function I get errors because it wants me to use long integers, which are too small for the numbers I want to work with.

How can I re-write this function to use GMP?

View 4 Replies View Related

C :: Changing Value Of A String Through A Pointer

Jun 11, 2013

Basically, I have a pointer to a C string:

Code: char **objectData and a C string:

Code: char temp[350]; I need to assign the CONTENTS of the temp to the CONTENTS to which objectData points.

Code: *objectData = temp; //this changes the pointer. When temp is deleted, objectData points to some rubbish

**objectData = *temp; //this doesn't seem to be doing anything - the string to which objectData points does not change.

View 3 Replies View Related

C :: Changing Program To Application?

Aug 22, 2014

I was wondering if there was a possible way to change my c program into an application so that i can send the application to another person and not let the other person have access to my codings?

My reasons for asking this question: For the application i want to send there are secrets that are meant to be unraveled by gameplay but i dont want people to look at the codes and know everything.

View 6 Replies View Related

C++ :: How To Get Numbers In Order But Not Changing Name It Goes With

Mar 13, 2014

SO lets say I have a file that says

10 tennent
9 Eccleston
12 Capaldi
11 Smith

How do I get the number's in order but not changing the name it goes with? SO here is how I started it

# include <iostream>
# include <fstream>
# include <sstream>
# include <set>
# include <list>
# include <string>
# include <cctype>
# include <vector>

[Code] ....

View 12 Replies View Related

C++ :: Changing Array Values

Jun 15, 2013

If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?

#include <iostream>
#include <math.h>
#include<iomanip>
#include <vector>
using namespace std;

[code]...

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved