the following short program asks user to enter # of hospital rooms (between 1-5), and asks for number of flowers, which cannot be a negative number. Then, it picks based on how many rooms the price from the `hospitalRoomsPrices_Array[5]`, and it also displays the total flowers multiplied by $2.50 each. finally, total cost of room(s) price + flower costs is added heres the code: #include<stdio.h> void getUserInput(int *numHospitalRooms, int *numFlowers); int main() { float hospitalRoomsPrices_Array[5]={300.00,350.00,400.00,450.00,500.00}; int numHospitalRooms = 0; int numFlowers = 0; float flowerPricing = 2.50; getUserInput(numHospitalRooms, numFlowers); float flowerCost = numFlowers*flowerPricing; float totalCost = (flowerCost + hospitalRoomsPrices_Array[numHospitalRooms]); // …

Member Avatar
Member Avatar
+0 forum 3

Hi, I am facing an issue in string to const char pointer conversion. I am doing stuff in the fun() but here i am just giving my example. Here it the code: // Helper function string fun() { string abc = "Daniweb"; // print here #1 return abc; } // main function int main() { const char * returnValue = fun().c_str(); // print here #2 string returnValue2 = fun().c_str(); // print here #3 } When I print the value in fun() function before returning it, it is printing fine. (#1) When I print the value after const char (#2), it …

Member Avatar
Member Avatar
+0 forum 13

I declared two different char * and initialised them to the same string. but i thought they would be pointing to the different addresses , but they pointed to the same addresses.. How come this happens? char* arr = "abcdefgh"; char* brr = "abcdefgh"; cout<<arr<<endl; cout<<brr<<endl; the values printed out were same.. How this is happening? Plz explain

Member Avatar
Member Avatar
+0 forum 4

In the following code I'm trying to make "SRAM", "FRAM", "EEPROM", and "FLASH" constants, MEM_TYPE an 8-bit variable that can be changed by other programs. The pointer should be pointing to MEM_TYPE. I'm getting a error under uint8_t (defined as BYTE elsewhere in an included file), "*", *and enum which is causing the rest to be errored as well. I copied the format of another's program that I can't post here. What am I really doing? And how do I fix it? uint8_t volatile * const enum { SRAM, FRAM, EEPROM, FLASH }MEM_TYPE;

Member Avatar
Member Avatar
+0 forum 1

Okay, so this is my current code: #include <stdlib.h> #include <stdio.h> #include <stdint.h> struct Display { int width; int height; char **array; }; struct Display *display_create(int width, int height) { struct Display *display = (struct Display *) malloc(sizeof(struct Display)); display->width = width; display->height = height; display->array = (char **) malloc(sizeof(char) * height); for (int i = 0; i < height; i += 1) { display->array[i] = (char *) malloc(sizeof(char) * width); } return display; } void display_destroy(struct Display *display) { for (int i = 0; i < display->height; i += 1) { free(display->array[i]); } free(display->array); free(display); } void display_clear(struct Display …

Member Avatar
Member Avatar
+0 forum 3

why this code not work ?? # include <stdio.h> void get_values(float *r, float *v); float do_calculations(float resistance, float voltage ) ; void display_answer(float current); main() { float resistor; float volts; float current; //explain_program(); get_values(*r, *v); current = do_calculations(resistor, volts); display_answer(current); } void explain_program() { printf("This program calculates the current in amps. \n"); printf("Please enter the value of R in ohms and v in volts .\n"); } void get_values(float *r, float *v) { float resistance; printf("\n\n Input the resistance in ohms = "); scanf("%f", &*r); // scan resistance printf("Input the voltage in volts ="); // scan volts scanf("%f", &*v); //*r = …

Member Avatar
Member Avatar
+0 forum 4

My Name is Leonard E. Norwood Jr. I'm Undergraduate student from Norfolk State University in Norfolk Virginia. Getting down to the point, my program is supposed to print out a list of pre-set numbers in reversal. I used pointers for this, however, something went wrong so I'm trying my best to trace this program and assume that there is something wrong with one of the for loops that is causing something to happen. This program can compile but nothing is happening, I just need some slight assitance. #include <stdio.h> { int i, j; float ar[5] = {12.75, 18.34, 9.85, 23.78, …

Member Avatar
Member Avatar
+0 forum 6

#include<iostream> using namespace std; int main(){ int fish =6; int * fishp = &fish; cout<<fishp<<endl; return 0;} this runs ok, but i get the same memory address when i cout either fishp or &fishp. how is it possible for a pointer to have the same address as the address it's pointing to?

Member Avatar
Member Avatar
+0 forum 6

I am implementing Priority QUE as a doubly linked list. My structs: typedef int kintyr; typedef struct qElem { struct qElem *prv; kintyr *dat; int *priority; }qElem; typedef struct que { qElem *fr,*bk; int cnt; }que; And this is my functions to create empty PQ, and to insert elements: que *qNew() { que *q = malloc(sizeof(*q)); if (q==NULL) return NULL; q->fr = NULL; q->bk = NULL; q->cnt = 0; qFault = 0; return q; } que *qEnq(que *q, kintyr *x, int *prrt) { que *zn=q; qFault = 0; if (q == NULL) { qFault = 1; return q; } if …

Member Avatar
Member Avatar
+0 forum 2

Hi there, I am having a problem of passing arrays to functions, here is my code: void zeroMatrix(float **arr); void main() { float e[2][2]; zeroMatrix(e); } void zeroMatrix(float** arr) { int i,j; for (i=0;i<2;i++) { for(j=0;j<2;j++) { *( *(arr +i)+j) =0; } } } The problem is I want to allocate dynamically an array and to pass to a function. Cheers guys

Member Avatar
Member Avatar
+0 forum 5

I need some pointers with pointers. What is the difference between a variable preceded by an "*" and an "&"? Some of my sample code uses one and some the other. I'm getting compiler errors trying both saying the variable is not defined. First use this function.

Member Avatar
Member Avatar
+0 forum 15

Hello, I was wondering what a second pair of eyes (or several) might have for opinions on this code? This program is supposed to store a user generated array, and functions which tell the highest, lowest, etc. Mainly, I need help with the "set cell" part, which is supposed to allow the user to access any cell in the array Thanks very much #include <iostream> #include "NumberArray.h" using namespace std; NumberArray::NumberArray(int s) { arrayPointer = new double [s]; // constructor size = s; } NumberArray::~NumberArray() { delete [] arrayPointer; array=NULL; if(arrayPointer!=NULL) //destructor { cout << "inside destructor, just checking" << …

Member Avatar
Member Avatar
+0 forum 1

How can I create an array of pointer using **P and point it to NULL? Let's say I have coded as below . struct s { float a ; char x ; } ; s **p ; p = new ( s * [10] ) ; Now I want to make some of them as NULL p[0] = NULL ; p[5] = NULL ; If I simply coded as above then it gives me a warning and also the above method is wrong in how it makes the variable NULL. So how to do I do this?

Member Avatar
Member Avatar
+0 forum 1

I have an abstract class CArticle and two derived classes CBook and CMagazine. I also have a class CLibrary where i want to add articles. Its members are an int variable to count the articles and a double pointer of CArticle. I have the following main function: int main() { CLibrary L1; CArticle *A1=new CBook(1000); CArticle *A2=new CBook(1001); CArticle *A3=new CMagazine(1002,3); CArticle *A4=new CMagazine(1003,6); CArticle *A5=new CMagazine(1004,8); L1.addArticle(A1); L1.addArticle(A2); L1.addArticle(A3); L1.print(); } I can't figure out what type of parameter should my addArticle() function have in order to work for this main. I would like to let the compiler choose …

Member Avatar
Member Avatar
+0 forum 16

Hello, First of all I want to thank all the help with my posts. I have a program where I have to convert a phrase from lower case to upper case, but I cannot use any of the toupper() isupper() functions and vice versa. I think I almost got it, but I know my for loop for the conversion is incorrect. Here is my code: #include <iostream> #include <string> using namespace std; int main() { char beach[] = "Take me to Clearwater Beach!"; cout << "Initial Phrase: " << beach << endl; for (char *i = beach; *i != '\0'; …

Member Avatar
Member Avatar
+0 forum 6

Hello, I have a program assignment that I have no idea what it's asking for honestly. I've tried to read all I can about it, but I do not understand. I tried my hand at some code, but it's only returning the address of course. Here is my attempted code: #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { int a[5]; int (*ptr_array)[5]; for (int i = 0; i < 5; i++) { cout << "Enter array value: " << endl; cin >> *ptr_array[i]; } cout << "The beginning of the array is: " << ptr_array << …

Member Avatar
Member Avatar
+0 forum 5

I have an array of elements. Think each of the element as competitors, and a tournament is going to rank them. The output of the program is showing elements at each level. Here's the code: #include <stdio.h> #include <stdlib.h> bool isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } // modified int log_2(unsigned int n) { int bits = 0; if (!isPowerOfTwo(n)) bits++; if (n > 32767) { n >>= 16; bits += 16; } if (n > 127) { n >>= 8; bits …

Member Avatar
Member Avatar
+0 forum 7

Need help writing a program for class. Here were the posted instructions: Step 1: The program should have a FUNCTION that displays a screen that shows which seats are available and which are taken. Seats that are taken should be represented by a # symbol and seats that are available should be represented by a * symbol. The first thing your program should do is initialize all of the seats to available (*) and display the seating chart. (HINT: The seating chart should be a two dimensional array.) Step 2: Each row in the auditorium has a different ticket price. …

Member Avatar
Member Avatar
+0 forum 1

hi i am really new to this and can't see why i can't get my code to work, it is probily really silly but help would be appreciated. i am trying to get the user to enter the number of competators of a 4 lap race so that it can determine the lap size then read in the lap times of each competator. # include <stdio.h> # include <malloc.h> /* define the structure , what you want the user to input*/ struct laptimes { float lap1; float lap2; float lap3; float lap4; }; int main (){ int comp ; int …

Member Avatar
Member Avatar
+0 forum 21

I REALLY NEED HELP WITH THIS QUSTION AND I ONLY HAVE 48 HOURS TO COMPLETE IT.. I DONT EXPECT ANY OF YOU TO DO IT FOR ME.. BUT I REALLY NEED SOMEONE WHO WOULD TEACH ME.. EMAIL : nifhail_torres@yahoo.co.uk As everyone knows that Malaysia is going to have the 13th general elections on 5th of May 2013. Therefore, you as a software engineer are required to develop the application system called Smart Registration System (SRS) for the 13th general elections. The purpose of SRS system is developed for election officer to store voters’ particular information in a sorted linked list …

Member Avatar
Member Avatar
+0 forum 3

I have this Singleton class called ZombieLand that is supposed to represent a 2D array. This 2D array is getting constantly updated and populated by different instances of my MachineState struct, which contain x and y coordinates to help me navigate through the 2D array. #pragma once #include "singleton.h" #include "machine.h" #include "traits.h" #include <list> class ZombieLand : public Singleton<ZombieLand> { DECLARE_SINGLETON(ZombieLand); public: MachineState * world [19][19]; bool map[19][19]; ZombieLand() { for(int i = 0; i<19; i++) { for(int m = 0; m<19; m++) { map[i][m] = false; } } memset(world,0,sizeof(world)); } MachineState *getField(int x, int y) { return world[x][y]; …

Member Avatar
Member Avatar
+0 forum 1

I have the following code.According to this the values of pointers p[0] and p[1] remains unchanged since the swap is made to local variables in swap function.Now my doubt is how can I swap the pointers p[0] and p[1] inside the function swap?? #include<stdio.h> int main() { char *p[2]={"hello","good morning"}; swap(p[0],p[1]); printf("%s %s",p[0],p[1]); return 0; } void swap(char *a,char *b) { char *t; t=a; a=b; b=t; }

Member Avatar
Member Avatar
-1 forum 1

Hi, I'm working on classes with pointers. I do have a main function that calls this. This program compiles. But the input from the user isn't getting passed to the other functions. The user_input function should take the response and pass it to the create_posting then it is outputted to the display function. I think the problem is in the user_input function but I've tried tweaking things and it still isn't working. Any tips are appreciated. class Posting { public: Posting(); //Constructor void user_input(char * input,char* &response); void create_posting(); private: char *type; char *info; char *place; char *email; }; Posting::Posting() …

Member Avatar
Member Avatar
+1 forum 3

Hello, I am working on an assignment. I am given the code below. I am trying to figure out what the line directly below is doing. Is this a functor? I am getting a compiler error saying the compiler expects a ';' before the '*'. I've searched for functor examples, but I am stuck. Do I need to define the pointer and/or function? I've tried different combinations, but no luck. virtual Do_Command * create_Do_Command (int num) = 0; #ifndef _FOO_FACTORY_H_ #define _FOO_FACTORY_H_ class FOO_Factory { public: Foo_Factory (void); virtual ~Foo_Factory (void) = 0; virtual Do_Command * create_Do_Command (int num) = …

Member Avatar
Member Avatar
+0 forum 1

So what would be the size of this array in bytes if on a 32 bit machine: double *arr[4] ;

Member Avatar
Member Avatar
+1 forum 4

`Inline Code Example Here`I am using a pair of pthreads that call a pair of functions for ping-pong dma data transfer that are used in a loop for data transfer from an acquisition board. For a large # of waveforms, I ultimately run out of PC memory and the program stops. At the end of each function I use the delete[] command to clear memory for reuse, but the pointer appears to advance by the array size used for the transfer until the location exceeds the 2 GB I have for memory. I can see this happening using the Task …

Member Avatar
Member Avatar
+0 forum 5

Hi guys What's the default pointer value in c++? Can I count on the compiler to set an uninitialized pointer to NULL? Is it compiler dependant? What's the "consensus"? Thanks! -FH

Member Avatar
Member Avatar
+0 forum 2

Hi, I've not worked in C, C++ from like 5-6 years. But now I got to do a very small change (explained below). I tried reading tutorials but only got confused. Below I've struct containing 2 attributes. I need to create its refrence and pass values to these 2 attributtes. File in which struct is defined. //List of includes typedef struct dscvs { UPD_TRC(trc_no); UPD_STS(status); }dscvs_i; File in which struct variable is used // Here I need to create a variable of type dscvs_i, so that I can feed the values inside UPD_TRC(trc_no) & UPD_STS(status); // This is what I'm …

Member Avatar
Member Avatar
+0 forum 1

//Bubble.h #include <iostream> #include <fstream> #include <cstdlib> using namespace std; struct nodeType { int info; nodeType *link; }; class Bubble { public: Bubble(); //constructor //deconstructor //copy constructor //operator= (overloading the = operator) friend istream & operator>> (istream &infile, Bubble & mylist); friend ostream & operator<< (ostream &outfile, const Bubble & alist); int size()const; void bubblesort(); private: nodeType *head_ptr; int manynodes; };

Member Avatar
Member Avatar
+0 forum 8

Hi I have trouble with implementing a dynamic two dimensional pointer array on allocating memory for it. I tried it this way but not sure if it's correct. The array should contain pointers to heap allocated **Integer** objects const int size = 10; Integer *** twoD; twoD = new Integer**(); for(int i = 0 ; i < size ; i++) *twoD[i] = new Integer(); for(int j = 0 ; j < size ; j++) twoD[i][j] = new Integer(); Any help will be appreciated!

Member Avatar
Member Avatar
+0 forum 5

The End.