C++ :: Using Pointers To Change Some Value On The Fly?
May 13, 2015
I've got an interface that provides the methods that are to be implemented
Code:
class A {
virtual void A() = 0;
}
class B : public A {
std::string operator<<(const std::string& lhs);
[Code] ....
I don't know why the << operator in B is never called..
View 5 Replies
ADVERTISEMENT
Jan 17, 2014
the book I learn from gave a task to write a program which gets a matrix , and we have to write a function that switches 2 columns or rows the user inputs .as far as I know a function can not change variables in the main function without using pointers .so , theoretically, can a function described here can be written without using pointers ? as far as I tried - it can not.
View 9 Replies
View Related
Dec 17, 2013
I have a linked list where each node contains a pointer to a string, I'm treating the linked list as a text file and each node/string contains each line in the text file.
I have all of that working, but now I need to create a switchLine function that takes in the two line numbers and I need to switch those lines in the text file. I initially thought of switching the pointers to each the next node in the linked list such that the node order changes, but I then realized how much work that would actually take when you need to consider so many cases. So I instead thought of changing the pointers to strings. If I want to switch the 2nd and 3rd line, then I'd want to have the 2nd node in the list have its char * pointer point to the memory position that the 3rd node's char pointer points to, and vice versa.
View 2 Replies
View Related
Feb 20, 2013
My coin/money change code works when there can be an exact change each time, i.e. when the 1 cent option is available. However, when the change options are only $10, $5, $1, 25 cents and 10 cents, it does not give me what I want for instance, I wanted to get change for $237.80, I was expecting to get:
23 10's, one 5, two 1's and 8 dimes. However, the code below is giving me 23 10's, one 5, two 1's and 3 quarters (there is no option left for the 5 remaining cents).how to fix it?
Code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void change(double cents, int a[]);
int main() {
double Dollars;
double cents;
[code]...
View 14 Replies
View Related
Feb 28, 2014
I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried
Code:
int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
[code]...
the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..
View 4 Replies
View Related
May 21, 2013
I am a little confused while comparing char pointers to integer pointers. Here is the problem:
Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";
When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;
As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};
If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??
View 2 Replies
View Related
Apr 15, 2013
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
View 3 Replies
View Related
Mar 6, 2015
how to use a keyboard. I have the program running now in Dev-C++, but the standard display letters on the monitor are small and sort of boring.Within a C program, is there a way to change the font to something stylish? Enlarge the letters? Change the color from letter to letter?
In the old days, there was graphics.h, but that isn't included now, and I would prefer to use some modern extension. I'd like to write it on Win7, then move it to Linux on Raspberry Pi. It would be nice to avoid a full-scale graphics system like OpenGL.
View 1 Replies
View Related
Nov 14, 2013
I have a .txt file which contains a large amount of ones and zeros (tile map for a game) and basically I just want to know how to change say just the 12th value in the file from a 1 to 0 .....
View 2 Replies
View Related
Sep 3, 2014
I am working on a program that is supposed to do I/O file streaming. I dont know if I can properly explain how its supposed to work but I have found the error on my code, I just dont know WHY the error is happening? If you look in the while loop, count changes values like it should, but MOVE and TIP doesnt. Count starts at value 2. So move is 108. Then count becomes 4, but move stays at 108?
tring rec;
fstream myfile("File.txt", ios::in | ios::out);
myfile.seekg(myfile.tellg(), ios::beg);
myfile.seekp(51, ios::beg);
[Code]....
The lines of code im getting errors on is
int move = count * 54;
int tip = move + 51;
Move wont change its value? It stays 108, causing this infinite while loop. Where is the error in my code to cause move to not change values like count does?
I seem to be struggling with I/O File streaming :(
View 2 Replies
View Related
Apr 24, 2014
How to change directory in c++ ( windows ) I want to go to the folder "example2" and I delete some files and then return to the original folder c++ - windows
View 7 Replies
View Related
Sep 26, 2012
this is the code:
Code:
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main () {
int result,i,j;
[Code] ....
and it doesn't find it. it says the the word:"Users" is incorrectly formed universal character name ....
View 2 Replies
View Related
May 19, 2013
how am i supposed to alter font size of text which appear in output screen?
View 1 Replies
View Related
Jun 15, 2013
if there is a program which i can use to change the name of a variable in a c program for example if i declare a variable like
Code:
int ch;
printf("%d", ch);
Can i later change the name of the ch variable to lets say "number" the code now becomes
Code:
int number;
printf("%d", number);
View 6 Replies
View Related
Oct 10, 2014
i have my basic C program here (i'm new to C language):
Code:
#include <stdio.h>
int main()
{
int grade;
int A=0;
int B=0;
int C=0;
int D=0;
int E=0;
[Code]....
As you can see, it's only for counting how many students got the grades from A to E, but the problem is that i need to change it from numbers into asterisk
for example: 4 students got the grade A, and 3 students got the grade B
instead of displaying
A=4
B=3
i want it to display
A=****
B=***
View 11 Replies
View Related
Jun 20, 2013
I have installed VS 2010 and VS 2012. VS 2012 uses SqlServer CE 3.5 and VS 2012 uses SqlServer CE 4.0.The problem is that when a project uses a 3.5 file it tries to open it with 4.0 even if the app.config says to use the 3.5 provider. The version of the assembly is pulled right out of the GAC. I uninstalled 4.0 and the reference auto updated its version to 3.5.1. However after installing 4.0 again it changes to 4.0. The error I am getting is that 4.0 cannot open a 3.5 file....they changed the file format from 3.5 to 4.0 and they are not compatible.
View 2 Replies
View Related
Dec 20, 2014
Is there a way to change the Font size using code?
View 5 Replies
View Related
Sep 4, 2014
On one of my assignments I have to find the optimal change. For example, if I were to have 70 cents and had only quarters, dimes and pennies, the best way to receive change using less coins all together would be 2 quarters and 2 dimes (4 coins all together should be displayed).
All in all, I understand my assignment, however there is something I don't know how to do (or can't recall how to) and that is finding the the highest number in an array to use in a function and be able to compare it.
#include<iostream>
using namespace std;
//function in which amount = money, changeArray is the array where money is stored,
//and numCoins the amount of coin types there are available in the array
int optimalChange(int amount, int * changeArray, int numCoins) {
[Code] .....
What I'm stuck with, is that I don't remember how to get the highest number from the array that way I can compare it with the total amount when I'm building my function. Also, the function has to call itself recursively.
View 1 Replies
View Related
Sep 13, 2013
So this is the code I have so far, I didn't know it had to be a dynamic array so how would I Utilize dynamic array allocation to size the modal array
#include <iostream>
using namespace std;
int main() {
const int arraySize = 25;
const int patternSize = 10;
[Code] ....
View 1 Replies
View Related
Oct 5, 2014
im new to c++ ,so my question is how do i change a length of a text. for example hi my name is blah blah blah. nice to meet you. (n i want every lines to have 8 chars how do i do that)
(hi__my__
name_is_
balh____
blah____
blah____
._nice__
to_meet_
you.) (_ equal space)
View 3 Replies
View Related
Sep 4, 2013
How to change what the cursor is in sfml 2.0?
View 1 Replies
View Related
Jun 16, 2014
I have a program with the following code, and I need to be able to either change the value of any or all of the strlen or to replace one or all with a temp array value. All values of the expression are arrays.
if (::strlen(tc_buf) + ::strlen(maxtime_buf) + ::strlen(" ") < sizeof(localBuf))
View 1 Replies
View Related
Feb 1, 2015
how can i change the array value and display the updated value. for example this is the output beginning of the program
-----------------------------------------------------
Part Description Number of parts in the bin
----------------------------------------------------
valve 10
Bearing 5
Bushing 21
Coupling 7
[Code].....
View 1 Replies
View Related
Mar 23, 2013
For particular assignment, I am asked to evaluate data from an inputfile, let it be named "infile.dat". Next, it is required to output to this same file, but with the name of this file altered to reflect the changes of data. For example, if I want to change the original file name to "changed_infile.dat.altered" by adding the "changed_" prefix and ".altered" suffix, how could this be done?
From my understanding, there are no functions in <fstream> that could change the file name. However, there is a rename function in <stdio>, but it's not exactly what I am looking for because I want to append a prefix and suffix to this existing inputfile name. Although I could apply a brute force method by simply doing rename("infile.dat", "changed_infile.dat.altered"), I want to have my program to work with various input files of different names.
View 1 Replies
View Related
Jan 5, 2015
I am building a tamagotchi like application/game. As for the leveling up and changing of character I am using a char value so that the icon can change as the character progresses.
Due to the fact that the value for level is changing I need it to also change for what is being used for the case statements
I know I cant use variables in case statements because I have tried every way I can think of.
The code is
switch(Area[y][x])
{
case '*':
Area[y][x] = Level;
break;
case 1:
{
CODE
}
}
Where I have the case 1 I need it to change as level increases (as level is starting at 1)
View 5 Replies
View Related
Feb 24, 2014
I'm creating a simpe program using Qt/C++ and MySQL.
I am trying to change row color of QTableView, but it has to change depending on value on the database.
For example I have QTableview wich is conected to mysql database:
this->model1 = new QSqlQueryModel();
model1->setQuery("SELECT ID, value, Name FROM DB_Table ");
ui->tableView->setModel(model1);
Now I want to change row color to red if the value = 1 .
I searched alot and found this:My link But dont understand how to use these clases in my code, i'm cind a new in programing.
View 3 Replies
View Related