?
Solved

function

Posted on 2005-03-20
9
Medium Priority
?
154 Views
Last Modified: 2010-04-01
Can any expert help me to answer this quesion please


write a member function MAP that maps each element of a sorted list    list1 to its factorial number and stors it in a new sorted list   list2

Example: MAP([1,2,3,4])=[1,2,6,24]

0
Comment
Question by:alnaqbi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
9 Comments
 
LVL 5

Expert Comment

by:beryl666
ID: 13586369
#include<iostream>
#include<conio.h>

using namespace std;
int map(int i);

int main()
{
int list1[5]={1,2,3,4,5};
int list2[5];

for(int i=0;i<5;i++)
list2[i]=map(list1[i]);

for(int i=0;i<5;i++)
cout<<list2[i]<<endl;;

getch();
return 0;    
}

int map(int i)
{
    if(i==0)return 1;
    else return re(i-1)*i;
}
0
 
LVL 5

Expert Comment

by:beryl666
ID: 13586372
sorry a bit error:
#include<iostream>
#include<conio.h>

using namespace std;
int map(int i);

int main()
{
int list1[5]={1,2,3,4,5};
int list2[5];

for(int i=0;i<5;i++)
list2[i]=map(list1[i]);

for(int i=0;i<5;i++)
cout<<list2[i]<<endl;;

getch();
return 0;    
}

int map(int i)
{
    if(i==0)return 1;
    else return map(i-1)*i;
}
0
 
LVL 5

Expert Comment

by:beryl666
ID: 13586381
is that what you want?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:alnaqbi
ID: 13614361
thanks beryl666 .. but this the error I got .. can you tell me how to solve it.. thanks



Compiling...
alnaqbi.cpp
c:\documents and settings\c4\desktop\alnaqbi.cpp(15) : error C2374: 'i' : redefinition; multiple initialization
        c:\documents and settings\c4\desktop\alnaqbi.cpp(12) : see declaration of 'i'
Error executing cl.exe.

alnaqbi.obj - 1 error(s), 0 warning(s)

0
 
LVL 5

Expert Comment

by:beryl666
ID: 13614906
// i guess you are using visual c++ > it will work now
#include<iostream>
#include<conio.h>

using namespace std;
int map(int i);

int main()
{
int list1[5]={1,2,3,4,5};
int list2[5];

for( i=0;i<5;i++)
list2[i]=map(list1[i]);

for(int i=0;i<5;i++)
cout<<list2[i]<<endl;;

getch();
return 0;    
}

int map(int i)
{
    if(i==0)return 1;
    else return map(i-1)*i;
}
0
 
LVL 5

Accepted Solution

by:
beryl666 earned 200 total points
ID: 13614912
//sorry again it should be

for(int  i=0;i<5;i++)
list2[i]=map(list1[i]);

for(i=0;i<5;i++)
cout<<list2[i]<<endl;;
0
 
LVL 5

Expert Comment

by:beryl666
ID: 13633472
can you get the answer right?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

752 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