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
ADVERTISEMENT
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
Aug 21, 2013
put enumerated data type in c++ for a poker program (specially for color and cardtype)?
Here are some codes:
//card.cpp
#include "cCard.h"
using namespace std;
cCard::cCard()
[Code]....
View 1 Replies
View Related
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
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
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
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
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
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
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
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
View Related
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
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
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
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
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
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
Feb 6, 2014
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS
[Code]....
View 2 Replies
View Related
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
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
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
Dec 7, 2014
I cannot figure out how to iterate and enumerated type. So the question that I am trying to solve is this:
Write an enumerated type definition for the four seasons, starting with Winter and ending with Autumn
View 2 Replies
View Related
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
Jun 26, 2014
How do I compare a string vector against an enumerated type? My code so far is:
void convertToLastFirst(vector<string>&names){
enum NameFormat{FIRST, LAST};
for (size_t i = 0; i < names.size(); i ++){
if (names[i] FIRST){
names[i] = LAST;
}
}
}
View 1 Replies
View Related
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
May 4, 2013
How can we build unit-tests for functions of libraries, those with user-defined types used as their arguments ?
For example
CRecord func(Myclass * class, BSTR * name, CComptr<xxx> & something);
View 9 Replies
View Related