Solved

HELP!

Posted on 2004-04-12
8
238 Views
Last Modified: 2010-04-01
Need help in correcting these codes.  Below are 4 independant files with the generated output to each.  Please help in providing corrected actual codes.  Thank you.

// ver5.cpp
#include <iostream>
#include <cmath>

using namespace std;

void input fun(p_array);
double calculate fun(p_array);

int main() {


   double p_array[2][3]; // data structure, memory location for your variable
   double d;

   input fun(p_array);
   calculate fun(p_array);
   print fun(double d);

   d = calculation function;

   print fun(d);

   return 0;

}

ver5.cc:6: `p_array' was not declared in this scope
ver5.cc:6: variable or field `inputFun' declared void
ver5.cc:7: `p_array' was not declared in this scope
ver5.cc: In function `int main()':
ver5.cc:15: variable or field `inputFun' declared void
ver5.cc:15: initialization to `int' from `double (*)[3]' lacks a cast
ver5.cc:16: initialization to `double' from `double (*)[3]'
ver5.cc:17: parse error before `)'
ver5.cc:19: `calculation' undeclared (first use this function)
ver5.cc:19: (Each undeclared identifier is reported only once
ver5.cc:19: for each function it appears in.)
ver5.cc:19: parse error before `;'
ver5.cc:21: `print' undeclared (first use this function)

// ver_6.cpp
#include <iostream>

using namespace std;

void input_fun(double p_array[2][3]);
double calculate_fun(double p_array[2][3]);
void print_fun(double distance);

int main() {

   double p_array[2][3];
   double distance;

   input_fun(p_array);
   distance = calculate_fun(p_array);
   print_fun(distance);

   return 0;

}

void input_fun(double p_array[2][3]) {

   for(int i = 0; i <= 1; i++)
       for(int j = 0; j <= 2)
            cin >> p_array[i][j];

}

double calculate_fun(double p_array[2][3]) {

   double distance;
     
   distance =

   return distance;

}

void print_fun(double distance) {

   cout << "distance = " << distance << endl;

}

ver_6.cpp: In function `void input_fun(double (*)[3])':
ver_6.cpp:27: parse error before `)'
ver_6.cpp:38: parse error before `return'
ver_6.cpp:42: parse error before `{'

// ver_7.cpp
#include <iostream>

using namespace std;

int main()
{
   point p_array[2];
   double distance;
   inputFun(p_array);
   distance = calculate_fun(p_array);
   printFun(distance);

   return 0;

}

ver_7.cpp: In function `int main()':
ver_7.cpp:9: `point' undeclared (first use this function)
ver_7.cpp:9: (Each undeclared identifier is reported only once
ver_7.cpp:9: for each function it appears in.)
ver_7.cpp:9: parse error before `['
ver_7.cpp:11: `p_array' undeclared (first use this function)
ver_7.cpp:11: implicit declaration of function `int inputFun(...)'
ver_7.cpp:12: implicit declaration of function `int calculate_fun(...)'
ver_7.cpp:13: implicit declaration of function `int printFun(...)'

// ver_8.cpp
#include <iostream>

using namespace std;

int main()
{
   DistanceOfPoints obj_1;
   obj_1.inputFun();
   obj_1.calculateFun();
   obj_1.printFun();

   return 0;

}

ver_8.cpp: In function `int main()':
ver_8.cpp:7: `DistanceOfPoints' undeclared (first use this function)
ver_8.cpp:7: (Each undeclared identifier is reported only once
ver_8.cpp:7: for each function it appears in.)
ver_8.cpp:7: parse error before `;'
ver_8.cpp:8: `obj_1' undeclared (first use this function)






0
Comment
Question by:edelossantos
  • 5
  • 3
8 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10810580
>>void input fun(p_array);
>>double calculate fun(p_array);

You r function names have a space in betwenn
These should be
void inputfun(p_array);
double calculatefun(p_array);

Also, the above declaration should contain the data type as parameter rather than the array p_array
Thus as per your main declaration, it should be
void inputfun(double p_array);
double calculatefun(double p_array);

print fun(double d);      ->>>> U have have not declared printfunc()




Amit
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10810587
void input_fun(double p_array[2][3]) {

   for(int i = 0; i <= 1; i++)
       for(int j = 0; j <= 2)
            cin >> p_array[i][j];

}


The last condition in for loop for j is missing

Amit
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10810591
double calculate_fun(double p_array[2][3]) {

   double distance;
     
   distance =

   return distance;

}


The statement 'distance = '   is incomplete

Amit
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10810603
int main()
{
   point p_array[2];
   double distance;
   inputFun(p_array);
   distance = calculate_fun(p_array);
   printFun(distance);

   return 0;

}



You have not declared point as a structr OR a class
point is not a standard/primitive data type as an int OR char OR float , so u should declare it first

Amit
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10810618
nt main()
{
   DistanceOfPoints obj_1;
   obj_1.inputFun();
   obj_1.calculateFun();
   obj_1.printFun();

   return 0;

}

ver_8.cpp: In function `int main()':
ver_8.cpp:7: `DistanceOfPoints' undeclared (first use this function)
ver_8.cpp:7: (Each undeclared identifier is reported only once
ver_8.cpp:7: for each function it appears in.)
ver_8.cpp:7: parse error before `;'
ver_8.cpp:8: `obj_1' undeclared (first use this function)



DistanceOfPoints    is not a primitive type, so either declae it as a struct OR class OR typdedef it as long, doubl,e int. char ect

Amit
0
 
LVL 4

Accepted Solution

by:
booki earned 500 total points
ID: 10810655
edelossantos,

OK, here's ver5.cpp:

// ver5.cpp

#include <iostream>
#include <cmath>

using namespace std;

void input_fun(double p_array[2][3]);
double calculate_fun(double p_array[2][3]);
void print_fun(double distance);

int main() {
   double p_array[2][3]; // data structure, memory location for your variable
   double d;

   input_fun(p_array);
   calculate_fun(p_array);
   d = calculate_fun();
   print_fun(d);
   return 0;
}

void input_fun(double p_array[2][3]) {
   for(int i = 0; i <= 1; i++)
       for(int j = 0; j <= 2; j++)
            cin >> p_array[i][j];
}

double calculate_fun(double p_array[2][3]) {
   double distance;
//   distance =
// ******* Looks like your friend hasn't finished implementing this function.
// ******* It needs to be completed.
   return distance;
}

void print_fun(double distance) {
   cout << "distance = " << distance << endl;
}

// end ver5.cpp

b.
0
 
LVL 4

Expert Comment

by:booki
ID: 10810687
edelossantos,

Ok,  let me see if i got this right.  ver5 through ver8 seem to be different versions of the same program.  All of them incomplete.  ver5 through ver7 seem to be attempting the same implementation.  ver8 is attempting to use objects however no objects are defined.  The code (ver5.cpp) that I posted is the same for ver5 through ver7.  ver8 is lacking the implementation of your object.  Otherwise it looks ok.

b.
0
 
LVL 4

Expert Comment

by:booki
ID: 10810695

Correction to ver5.cpp:

int main() {
   double p_array[2][3]; // data structure, memory location for your variable
   double d;

   input_fun(p_array);
   d = calculate_fun(p_array);  // <=== this line changed
//   d = calculate_fun();   <=== delete this line
   print_fun(d);
   return 0;
}
 
b.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now