C/C++ :: Pointers In Relation To Data Types?

Mar 7, 2014

how to correctly use pointers within relation to function parameters and main source file.

I noticed that char types, for example char myVariable[50]; which is an array, does not seem to require a pointer as if it already has one built in? as opposed to char *myVariable; which seems to need one - i assume this is because char has different ways to store memory in relation to pointers, because of there being multiple ways to store a string, and memory allocation as a part of that. - i stared C a few weeks ago and feel that it is difficult to progress without nailing down pointers. Also address operators provide confusion for me and written tutorials are not so clear because there are different ways to use these operators.

View 4 Replies


ADVERTISEMENT

C++ :: Using New On Primitive Data Types

Dec 12, 2014

int* count;
count = new int(1); // what???

Is this on the heap?? do i have to delete it now?

So is 'new' on a primitive data type just a way for me to allocate primitive data types (int, char, etc.) on the heap instead of the stack?

And, out of curiosity, can you do that in Java?

View 4 Replies View Related

C++ :: How To Convert Data Types

Jan 9, 2015

How to convert these data types? i have an array of bytes in unsigned char[] array, and need to convert to const void* pointer.

View 3 Replies View Related

C++ :: Object That Contains 2 Types Of Data

May 24, 2014

How do you create an object (like in the title) something more simple than a struct? I wanna know that cuz I'm writing a function that could return a boolean and an integer at the same time.

View 2 Replies View Related

C++ :: What Are The Implications Of Declaring Data Types But Never Using Them

Mar 26, 2013

What are the possible problems if I declare a bunch of data types and never use them? Do they take up a lot of memory? Will they slow run time? If it is an array do I have to delete it at the end of the program? What if the array is defined inside a class and never used? Do I still have to delete it?

i.e.

Code: class declarearrays{
public:
double **darray;
double **darray2;
void function1();//function that initializes darray
void function2();//function that initializes darray2 with different parameters, may not be used.
};

View 1 Replies View Related

C++ :: Map Storing Multiple Data Types

Jul 11, 2014

I am trying to create a generic map container which shell contain data of different datatypes. I already found a solution in this forum here:

[URL]...

Introducing a container with a Base Class as content type and inserting objectes of Derived Class types from that Base Class suites my implementation very well. But it is not really working. I implemented it this way:

class MyType {
public:
MyType() {}
virtual ~MyType() {}
}; template <class PT> class ParseType : public MyType

[Code]...

Then I insert one element.

// index being an object of type Parser<string>
ParseType<string>* test = new ParseType<string>( index );
// and index.val(0) = "-n"
iMap.insert( pair< string, MyType* >( index.id(0), test ) );

Now I think I should be able to call

const string key("-n");
iMap.at(key)->content->val(n);
Or
iMap.at(key)->get_val(n);

But neither one compiles with the error that "class MyType" (as the map container is pointing to a MyClass object) has no member/member function "content"/"get_val".

I also tried introducing member and member function "content" and "get_val" in "class MyType", which I thought should be hidden while constructing ParseType<string>. This would compile but it does not call the member "content or member function "get_val" from class ParseType.

A second try was to remove templatization of "class ParseType" and introduce a specific, let's say, "class ParseString" for objects of type Parser<string>. But the problems remain the same either the compiler complains due to missing member/member function or retreiving the map content will not call the derived class member/member function.

View 4 Replies View Related

C++ :: Handling Data Types As Inputs

Apr 10, 2013

I'm fairly new to C++ programming. I wanted to accept a datatype as an input. I've seen something similar while working with the <queue> library.

When defining a new object of queue

For example:

queue<int> Queue;

How is <int> handled ??

View 1 Replies View Related

C++ :: Accept Multiple Data Types

Jun 17, 2014

Basically I do not want to use a menu, instead just accept either an float or a single character. Then send the data to the appropriate spot based on the user input. I have been unable to convert the char to a float, and even if I did the char would probably only accept the first digit, say user enters '15' it would only read the '1'. I've tried strings instead of char but then unable to use the isalpha function. Do I need a char[] and then iterate through to get the numeric data? Then how do i make '1' and '5' become 15. There is probably a solution. I've also tried to use a loop waiting for the correct data while(!(cin >> letter)) which works but how do I get out if the user enters number.

#include <iostream>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;

[code].....

View 3 Replies View Related

C/C++ :: Arrays And Enumerated Data Types

Feb 18, 2014

I am doing a programming assignment. This program asks you to collect statistics on precipitation and temperatures from the four quarters of a year and print the calculated results. It is an exercise in using enumerated types and arrays. The measurements are entered at the end of every quarter.

Major variables (there are other variables) in the program:
Variable called: month of type Summary_Month (the enumerated type)
Arrays of integers called: low_temp, high_temp, precip
Array of doubles called: avg_temp

You will ask the user to enter the precipitation, low temperature and high temperature for each quarter. As you gather this data, you will calculate the average temperature (using avg_temp) for each quarter by averaging the low and high temperature for that quarter.

After you gather the information you will calculate and output : Total Precipitation for Year, Average Quarterly Precipitation, Average Quarterly Temperature, Highest Temperature for any quarter, Lowest Temperature for any quarter.

I am not getting the right output for average precipitation and temperature and I am not sure how to determine the highest and lowest temperature.

# include <iostream>
# include <iomanip>
using namespace std;
enum Quarters { March, June, September, December};
int main() {
const int NUM_QUARTERS = 4;

[Code] ....

View 9 Replies View Related

C/C++ :: Data Length Of Number Types?

Jan 22, 2014

What is the maximum and minimum of int, long int, long long int, double, float, and anything bigger than that? And also how to calculate this?

View 4 Replies View Related

C :: Switch To Different Data Types - How To Read One Parameter

Jul 11, 2013

Is there any way to make a switch in C. That I can choose between different data types? For example, at the moment I need to know how to read one parameter. It must recognize if it is a boolean or uint32.

View 4 Replies View Related

C++ :: Conversions Between Integer Primitive Data Types

May 8, 2014

In my platform (Windows 7 Ultimate 64 bits with Service Pack 1 over a compatible PC with a AMD x86 microprocessor), the next sample C++ code,

#include <iostream>
#include <limits>
using std::cout;
using std::endl;
using std::hex;
using std::showbase;
using std::numeric_limits;

[Code] ....

Compiled with Microsoft Visual C++ 2010 Express, prints this output:

ui = 0xffffffff
ull = 0xffffffff
sll = 0xffffffff
si = 0xffffffff
ull = 0xffffffffffffffff
sll = 0xffffffffffffffff

So, in my platform, conversion from an unsigend integer primitive data type to any bigger integer primitive data type never extends the most significant bit of the former integer and conversion from an signed integer primitive data type to any bigger integer primitive data type always extends the most significant bit of the former integer. This is convenient to mantain the same value when converting between integer primitive data types of the same signedness (i.e, signed integers or unsigned integers).

View 4 Replies View Related

C++ :: Reading Mixed Data Types From A File

Mar 28, 2015

How to properly read data from a .txt file.

If I have data stored in a .txt file, which is formatted/stored like this:

Code:
Apples and Strawberrys
10
Cherrys
12
Pears
16
Grapes, Melons, and Peaches
20

I know that if I read/extract, and print the data like this;

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream dataFile("test.txt");
string textData;
[Code] ....

Each line of data is stored in the string "textData" and printed to the screen, exactly as it was stored in the .txt file. So, all is clear to me up to that point.

But, what if I wanted to store each line of text in the string "textData", and store the numbers/integers into a separate variable called "numberData"? How would I retrieve and store the numbers (in the above example .txt file, every 2nd line) separately from the text?

For now, to keep things simple, let's assume that the data in the .txt file is stored/formatted as in my example (1 line of text, 1 line containing a number/integer, ...repeat) so, there is no need to test if the retrieved data is actually text or an integer, before it is stored in the appropriate variable type.

View 14 Replies View Related

C++ :: Error - Two Or More Data Types In Declaration Specifiers

Nov 24, 2014

i have the following error defines.h:14:23: error: two or more data types in declaration specifiers, the begining define.h source code is (the line 14 is in red):

Code:
/* $Id: defines.h 3492 2011-09-18 20:44:09Z nekral-guest $ */
/* some useful defines */
#ifndef _DEFINES_H_
#define _DEFINES_H_

[Code]....

View 8 Replies View Related

Visual C++ :: Arrays And Enumerated Data Types?

Feb 18, 2014

I am doing a programming assignment. This program asks you to collect statistics on precipitation and temperatures from the four quarters of a year and print the calculated results. It is an exercise in using enumerated types and arrays. The measurements are entered at the end of every quarter.

Major variables (there are other variables) in the program:

Variable called: month of type Summary_Month (the enumerated type)
Arrays of integers called: low_temp, high_temp, precip
Array of doubles called: avg_temp

You will ask the user to enter the precipitation, low temperature and high temperature for each quarter. As you gather this data, you will calculate the average temperature (using avg_temp) for each quarter by averaging the low and high temperature for that quarter.

After you gather the information you will calculate and output the following:

Total Precipitation for Year, Average Quarterly Precipitation, Average Quarterly Temperature, Highest Temperature for any quarter, Lowest Temperature for any quarter.

I am not getting the right output for average precipitation and temperature and I am not sure how to determine the highest and lowest temperature.

Code:
# include <iostream>
# include <iomanip>
using namespace std;
enum Quarters { March, June, September, December};
int main() {
const int NUM_QUARTERS = 4;

[code]....

View 3 Replies View Related

C++ :: Multi Data Types In A Line And Read To Struct?

Aug 14, 2014

How can I read this file in to my struct?

12345Joe Lim KH879.00
12233Kay Suet Yee35.98
23781Leong Jing Yang 10.00
67543Woon Tian Yi500.50
struct master {
unsigned short int IDnum;

[code]....

not working

View 16 Replies View Related

C++ :: Float And Double Data Types - Cannot Store Infinite Numbers

Sep 6, 2013

I was working on float and double data types and to see the results i wrote this program:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
ofstream outputF("output.txt");
double a = 1;
double outcome;

[Code] ....

Well I understand the part it cannot store infinite numbers. but if you take a look at the output for example (since it is too long i just added some of the outputs)

//---------------------
for the value of : 001
1
//---------------------
for the value of : 002
0.5
//---------------------
for the value of : 003
0.3333333333333333148

[Code] ....

if you look carefully at the value "5" and "10" results. it is awkwardly abnormal. which is something i couldnt understand. also it is the same with value "20", "25", "40", "50" and so on.

View 5 Replies View Related

C++ :: Design Image Class Which Should Work With Various Data Types (Multidimensional)

Dec 2, 2013

I have been thinking about this all day and I am yet to come up with a good solution. So, I need to design an image class which should work with various data types (int, float, double etc.) and can also be multidimensional (2, 3, 4, 5). So, what I did was generate a template image class as follows:

Code:
template<typename T, int dimensions=3>
class Image {
private:
T * data;
};

Anyway, now I have various image formats that I want to support, so the easy thing to do is create a Factory sort of object which will call eventually generate the correct image.

So I want to create various image classes called ImageType1, ImageType2 etc. which will take the input image and generate the correct Image object. However, I do not want these objects to be templated because they need to be passed from functions and be used in a generic way.

So, at run time I will need to be able to do this…

Code:
class ImageType {
public:
ImageType() {
PolymorphicImage * image = new Image<float, 3>();
}
private:
PolymorphicImage * image;
};

So, I want my ImageType classes to contain the Image object and be able to generate it with the right template arguments at run time. Is there any way to do this without having multiple specialised definitions for ImageType?

View 2 Replies View Related

C++ :: Dynamic Password Guessing Program - Conflict Between Data Types

Mar 17, 2015

I'm trying to develop a deeper knowledge of how loops work (and what better way todo that than a dynamic password guesser). My main problem lies with the conflict between data types, as I try to point to a char at a specific index position of the password guess.

See in my code (at line 57):

Code:
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
string AlphaNum("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");//62 possible characters
int size = AlphaNum.length();//should be 62

[Code] ....

This is annoying, because strings are arrays of characters themselves.

View 14 Replies View Related

C++ :: Relation Between A Container And Allocator

Mar 30, 2014

To my understanding, a Container should have an Allocator member data, which is used internally.

Question: what happens, for example, when we swap() two containers that use different allocators?

Must the allocators be swapped as well?

Must all elements of the container be reallocated when the allocator is changed?

View 7 Replies View Related

C++ :: Creating Binary Tree Program - Allow User To Input Data Types

Apr 23, 2013

In class we were asked to create a C++ BTree program that would allow a user to input the following data types and then store said data in a .txt file:

0. ID 8 bytes

1. First name 30 char

2. Last Name 30 char

3. Street Address one 30 char

4. Street Adress two 30 char

5. City 30 char

6. State 20 char

7. Zip 10 char

8. Country 30 char

(I'm not particularly asking for full code, pseudo code would also be great). I had a great deal of my work done, unfortunately, the computer I was working on crashed, corrupting my files.

View 4 Replies View Related

C++ :: Relation Between Local Position And Distance

Feb 21, 2014

i have two point P1 and P2 where i want to move P1 and P2 with keeping the distance and the position of the P2 relative to P1 i thought that when i keep the distance between the two point that involve keep in the same time the local position of P2 but when tested it does not work initial position of P1=(10.0f, 00.0f, 00.0f) initila position of P2 relative to p1 =(50,10,-8) we can get the global position of p2 ----- final position of P1 =(50,10,-8) final position of P2 in the world space =(40.31,8.06,-6.45) then we calculate the distance before and after we found that there are equal but when we calculate the position of p2 relative to p1 after and before we found that there are not equal.

how i can keep the local position and distance ?

View 14 Replies View Related

C++ :: Relation Between Allocator And NodeAllocator In A Container?

Mar 31, 2014

Consider a singly-linked list container.

Being constructed with an alloc<T>, it will rebind it as alloc<node<T>> for internal use.

Question: is allocator_type the same as alloc<T> or as alloc<node<T>>?

View 2 Replies View Related

C :: How To Print The Max Number Row In Relation To The Char Arrays Row

Mar 30, 2013

I have most of the code working properly, but I'm having trouble with a certain area. Currently I have multiple 2D arrays. One is a char array and the other is an int array. In the int array I have to find the max number in each column, which I've done. The problem is, I need to print the max number's row in relation to the char array's row.

For example,

Code: int array[2][3] = {60 50 30 0 100 1}

The max numbers are 60, 100, 30.

char array[2][length+1] = {nameOne nameTwo}

How it needs to print:

nameOne has max score of 60.
nameTwo has max score of 100.
nameOne has max score of 30.

I just can't understand how to compare the two arrays in the right way, so it'll know that nameOne is associated with the numbers in row 0 and nameTwo in row 1, etc.

View 1 Replies View Related

C :: Parameter Names Without Types And Conflicting Types In Fgets

Jan 22, 2014

I have this

Code:

#include<stdio.h>
#include<ctype.h>
#include<string.h>

int check_up(char string[]);
int check_low(char string[]);
void to_up(char string[]);
void to_low(char string[]);

[Code] .....

When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function

View 7 Replies View Related

C/C++ :: Using Pointers To Enter Data?

Nov 6, 2013

I want to do simple program to capture some 5 surnames of people(employees) - using array and pointers. Well I understand a bit of arrays and I know how to loop through.

How can achieve this? This holds the key to my understanding how pointers work and can be used with char or strings.

View 2 Replies View Related







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