English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Please help me with this array declaration problem.

Write array declarations for the following:
a. a list of 100 double-precision voltages
b. a list of 50 double-precision temperatures
c. a list of 30 characters, each representing a code
d. a list of 100 integer years
e. a list of 32 double precision velocities
f. a list of 1000 double-precision distances
g. a list of 6 integer code numbers

2007-05-04 08:55:36 · 2 answers · asked by frank 1 in Computers & Internet Programming & Design

2 answers

Frank,
I take it from you questions that you are just starting out in C++.
I also take it from you questions that you are not prepared to answer them.

So my next question is what the hell are you doing on a C++ course?
If you are not prepared to take the time and trouble to attempt these simple, yes simple, questions then I would seriously think about dropping the course now.

2007-05-04 09:13:56 · answer #1 · answered by AnalProgrammer 7 · 0 0

Well the first thing you need to decide is if you want to use native C++ arrays (built-in to the language, fixed size, declared like "int x[2]") or STL vectors (more powerful, standard library class, re-sizable). For now we'll assume you want standard c++ arrays.

(a) list of 100 double voltages

//standard declaration
double voltages[100];
voltage[0] = 4.5;
voltage[1] = 3.2;
....

//OR initializer list

double voltages[] = {4.5, 3.2, ..........};

(b) same as (a) except only listing 50 values in the declaration or initializer list

(c)

char codes[30];
code[0] = 'a';
....

//OR
char codes[] = { 'g', 'c', 't', 'a', 'c' };

(d)
int years[100];
//you get the idea

You can figure out the rest

2007-05-04 16:45:22 · answer #2 · answered by tvh2k 2 · 1 0

fedest.com, questions and answers