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
ADVERTISEMENT
Feb 3, 2013
I got the following lines of code from a book. The variable char c is being used here to demonstration local variable declaration.
while(char c = cin.get() != 'q') {
cout << c << " wasn't it" << endl;
if(char x = c == 'a' || c == 'b')
cout << "You typed a or b" << endl;
else
cout << "You typed " << x << endl;
}
It compiles and runs. There are two issues when I try to run it.
1) It seems to loop through two times for every entry. If I insert cin.ignore() just before the closing bracket, it seems to work better.
2) the variable c does not seem to have the character I entered when examined in the if statement.
What is happening with the variable c inside the while loop scope?
Does c actually get initialized?
View 2 Replies
View Related
Feb 18, 2013
what is the empty state of queue?
View 5 Replies
View Related
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
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
View Related
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
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
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
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
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
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
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
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
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
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
Oct 23, 2013
line 27 and line 88 Im having a hard time figuring it out what the error is.
#include<iostream>
#include <cmath>
#include<algorithm>
[Code]....
View 2 Replies
View Related
Mar 29, 2014
I keep getting an error here and cant quite figure out why,
Code:
else if (mainMenu == 3){
cout << "Please make a selection" << endl
<< " 1) Withdraw from account" << endl
<< " 3) Back to main menu" << endl;
cin >> withdrawMenu;
if (withdrawMenu == 1){
[Code] ....
View 1 Replies
View Related
Apr 3, 2014
I am making a program that allows you to add two big numbers that are larger then what int can handle together. I think I have done everything to accomplish this but when I try to instantiate the program I get a error Expression must have a class type.
Here is my main file that is supposed to instantiate the program.
Code: #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <conio.h>
#include "LargeIntegers.h"
using namespace std;
[code]....
View 10 Replies
View Related
Jun 18, 2014
I wrote a program, that generates 20 random integers, and stores them in an array. Then I decided, to build more functions to it, i.e why not have it to display the lowest integer of an array. I created my function,
Code:
int minValue( int field[ ] )
and got my code in side, which (technically) works. In my main() function I'm calling
Code:
printf( "The smallest value of an array is: %d
", minValue( field[] ) );
and I'm getting an error trying to compile it.
Code:
randomArray.c:62:74: error: expected expression before ']' token
printf( "The smallest value of an array is: %d
", minValue( field[] ) );
View 2 Replies
View Related
Oct 23, 2013
I am trying to create a NFA from a regular expression. I have a grasp on reading in the regular expression and being able to make a stack from it. The part I am struggling on is mapping the characters in the regular expression to an integer indicating the variables order in the expression. I am just not sure how to go about this.
My code so far...
Code:
#include<stdio.h>
#include<stdlib.h>
#include "stack.h"
int main(void)
{
char expression[80];//array to store regular expression
[Code] .....
View 6 Replies
View Related
Feb 3, 2013
I am using code::blocks for c programming and when i take debugger in below code it show ..
a syntax error in expression near "if"..
I am just checking debugger ...
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char s1[100];
[Code] ....
View 7 Replies
View Related
Mar 6, 2015
I would like to ask about how we calculates the following bitwise expression.
Code:
unsigned char ch[2] = {0x49,0x49};
ch[0] | ch[1] << 8; I'm thinking ch[1] << 8 as 0x00 ...
So, I think that the above expression converts to 0x49 | 0x00 ... and the complete expression should be 0x49 for me.
But, the compiler gives me the result of 0x4949 as two bytes.How does the compiler calculate this expression as two bytes?show me the steps included in the calculation of this expression?
View 2 Replies
View Related
May 26, 2014
This is what i have example code in c++:
#include <iostream>
class Foo{
public:
void bar(){
std::cout << "Hello" << std::endl;
[Code] ....
After compiling it is giving error as :
foo.cpp: In function ‘int Foo_max(Foo*)’:
foo.cpp:26:37: error: expected primary-expression before ‘int’
foo.cpp:26:46: error: expected primary-expression before ‘int’
View 6 Replies
View Related
Dec 17, 2014
How is the definition of the term "expression" affected by value returning functions, and why?
View 5 Replies
View Related
Jan 15, 2015
I am a c++ leaner, I am trying to create a BST tree for this expression: 2346*+/8+, and do inorder and postorder to get the in-fix version, and postfix version of the expression. I am having difficulty to create the binary tree for the expression. Here is my peso code:
Tree:
Stack:
inorder fn{}
postorder fn{}
main{
input the file;
while(expression){
[Code] ....
The tree I want to create is like this
+
/
(/) 8
/
+ 2
/
* 3
/
4 6
My problem for this code is that after create (4*6) tree, I cant link (+3) with (4*6).
View 1 Replies
View Related
Aug 4, 2014
Why do I get the error 'rec' cannot appear in a constant-expression ?
I have the following definitions:
... string rec[6];
list<rec> musicList;
...
View 17 Replies
View Related