?
Solved

function

Posted on 2005-03-20
9
Medium Priority
?
155 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
  • 6
7 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.
Suggested Courses

616 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