C++ program
1
Name:
Anonymous
2010-11-09 13:33
In C++, write a program that declares an array named myArray with 8 components of the type double. Initialize the array to 8 values that the user will input. Finally, pass the array as a parameter to a new function called printAllElements. This function will display values of each element in the array. You must use a separate function to print the elements.
2
Name:
Anonymous
2010-11-09 14:26
help
3
Name:
Anonymous
2010-11-09 14:30
Do your own homework.
4
Name:
Anonymous
2010-11-09 14:36
this is pretty simple
T array[8] = {0};
void pussyfoot (T* nigger) {for (int i = 0; i<8; i++) print (nigger+i)};
void print (T* polish) { std::cerr << *polish;};
int main (int argc char** argv) {
pussyfoot(array);
return 0;
}
5
Name:
Anonymous
2010-11-09 14:40
#include <iostream>
#define ELEMENTS 8
using namespace std;
void printAllElements(double array[], int size) {
cout << "Elements: ";
for(int i = 0; i < size; i++)
cout << array[i] << ' ';
}
int main() {
double myArray[ELEMENTS];
for(int i = 0; i < ELEMENTS; i++) {
cout << "Number " << i + 1 << '?' << endl;
cin >> myArray[i];
}
printAllElements(myArray, ELEMENTS);
}
6
Name:
Anonymous
2010-11-09 14:55
Something like this.
[m] #include <stdio.h>
double *inputDoubles(){
char stack[1000];
double i[8];
char is_safe[1000];
for(int myArray=1;myArray<=8;myArray++){
printf(" ");
scanf("%lf",&myArray[i] );
}
return i;
}
void printDoubles(double *myArray){
for(int i=1;i<=8;i)
printf(" %lf\n",i++[myArray]);
}
int main(){
double *myArray;
printf("Please input 8 numbers:\n");
myArray=inputDoubles();
printf("You entered:\n");
printDoubles(myArray);
return 1;
}[/m]
7
Name:
Anonymous
2010-11-09 14:55
Well, fuck me
Something like this.
[m]
#include <stdio.h>
double *inputDoubles(){
char stack[1000];
double i[8];
char is_safe[1000];
for(int myArray=1;myArray<=8;myArray++){
printf(" ");
scanf("%lf",&myArray[i] );
}
return i;
}
void printDoubles(double *myArray){
for(int i=1;i<=8;i)
printf(" %lf\n",i++[myArray]);
}
int main(){
double *myArray;
printf("Please input 8 numbers:\n");
myArray=inputDoubles();
printf("You entered:\n");
printDoubles(myArray);
return 1;
}
[/m]
8
Name:
Anonymous
2010-11-09 14:58
>>7
code tags are for code
9
Name:
Anonymous
2010-11-09 14:59
10
Name:
Anonymous
2010-11-09 19:59
#include <stdio.h>
void printAllElements(double *a, size_t n)
{
size_t i;
for (i = 0; i < n; i++)
printf("%f\n", a[i]);
}
int main(void)
{
double myArray[8] = {0};
size_t i;
for (i = 0; i < sizeof(myArray) / sizeof(*myArray); i++)
scanf("%lf", &myArray[i]);
printAllElements(myArray, sizeof(myArray) / sizeof(*myArray));
return 0;
}
11
Name:
Anonymous
2010-11-09 21:21
lol @ everyone posting C
12
Name:
Anonymous
2010-11-09 22:32
>>11
Because nothing whatsoever in the requirements gave any reason to use Sepples.
13
Name:
Anonymous
2010-11-09 23:26
>>11
These will all compile and work perfectly in any standard-compliant C++ compiler.
14
Name:
Anonymous
2010-11-10 1:30
>>9
Is this all you noticed? Returning address of local? Arrays starting with 1? You have been trolled by your mother and father who bore you an idiot.
15
Name:
Anonymous
2010-11-10 10:55
>>14
The lack of proper code tags is severely inhibiting my ability to properly look at the source.
16
Name:
Anonymous
2010-11-10 11:42
#include <iostream>
#include <vector>
using namespace std;
typedef vector<double> DoubleVec;
template <class T>
void printAllElements(const T& container)
{
typename T::const_iterator i = container.begin();
const typename T::const_iterator e = container.end();
while (i != e)
{
cout << *i << endl;
++i;
}
}
int main(void)
{
DoubleVec db;
while (db.size() < 8)
{
double temp;
cout << "Please input a number: ";
cin >> temp;
db.push_back(temp);
}
printAllElements(db);
return true;
}
17
Name:
Anonymous
2010-11-10 11:43
>>16
Like straight out of a Sepples-book.
18
Name:
Anonymous
2010-11-10 11:47
>>16
Made the important modification of db to myArray for ya.
#include <iostream>
#include <vector>
using namespace std;
typedef vector<double> DoubleVec;
template <class T>
void printAllElements(const T& container)
{
typename T::const_iterator i = container.begin();
const typename T::const_iterator e = container.end();
while (i != e)
{
cout << *i << endl;
++i;
}
}
int main(void)
{
DoubleVec myArray;
while (myArray.size() < 8)
{
double temp;
cout << "Please input a number: ";
cin >> temp;
myArray.push_back(temp);
}
printAllElements(myArray);
return true;
}