C++ homework

Can sombody help me in this homework

http://i40.tinypic.com/2hrdgfq.png
What kind of help do you need?

-Albatross
i dont now how to write the code in c++
Write what you are able to do then ask about specific parts you are stuck on. Writing the main function is a good start.

We wont do your homework for you.
i write the code but im stuck in the part of using only one subprogram

here the code that i have write but it is incorrect

#include<iostream>
using namespace std;

double Shuma(int a,int b,int c, int d);
double Prodhimi(int a,int b,int c, int d);
int main ()
{
int n;
double PRUSHI;
cout<<"jepe vleren e n:";
cin>>n;
PRUSHI=Shuma(2,n,1,3)+2*Prodhimi(0,n-1,1,1)+3*Shuma(1,6,1,2)+Prodhimi(4,n+1,1,3);

cout<< "Vlera = " << PRUSHI;
cout<<endl;
system("pause");
return 0;
}
double Shuma(int a,int b,int c, int d)
{

int i;
double S;
S=0;
for(i=a;i<=b;i++)
{
S=S+(c*i+d);
}
return S;
}
double Prodhimi(int a,int b,int c, int d)
{
int i;
double P;
P=1;
for(i=a;i<=b;i++)
{
P=P*(c*i+d);
}
return P;
}
can somone help me ?
Why no one is helping
1. This is really messy code and difficult to understand.
2. You are not giving us any info besides "it's wrong". Are you experiencing the error during compilation, and if so, please include the error message from the compiler.
3. It would be best if you told us what the program is supposed to do, because it will help everyone understand what you are trying to do better.

Please read the guidelines for posting in the forum.
For reference:
Σ = https://en.wikipedia.org/wiki/Summation#Capital-sigma_notation (what you want "Shuma()" to do)
Π = https://en.wikipedia.org/wiki/Multiplication#Capital_Pi_notation (what you want "Prodhimi()" to do)

Clearing up the English:
"To calculate the sums and products use only one subprogram named PRUSHI"
less English:
"To calculate the Σs and Πs use only one subprogram named PRUSHI"

To combine "Shuma()" and "Prodhimi()" into a single subprogram "PRUSHI()":
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int PRUSHI(int a, int b, int c, int d, bool mode); //mode determines whether to Σ or Π
//stuff
int PRUSHI(int a, int b, int c, int d, bool mode)
{
   int value; //"vleren" in Albanian? Russian? Some other language?
   if (mode)
   {
      //calculate "value" using Σ aka Shuma()
      return value;
   }
   else
   {
      //calculate "value" using Π aka Prodhimi()
      return value;
   }
}


Finally both your Shuma() and Prodhimi() subprograms are correct but
Prodhimi(4,n+1,1,3)
should be
Prodhimi(4,n+1,1,-3)
However since the Prodhimi() subprogram will no longer exist when you are done rewriting your code this isn't much of a problem.

@heyyou
1. Code seems clear enough to me? The English not so much but cut the guy some slack he's Albanian or something.
2. Program produces incorrect output (just copy and compile). However if you're unfamiliar with Σ and Π notation then I can understand why you'd want clarification.
3. See OP, though again you need to be familiar with Σ and Π notation.
@heebleworp

I never said anything about his English, only his code. And taking a second look, I guess the only messy part is the brackets, so I retract my statement about the code, my apologies.

I do still think that some context is best, however.
@heebleworp

Yes im albanian , thenks that you help me .

But im beginner on c++ and i dont now how to complet this homework

Can you help me
http://www.translate.com/
First create a subprogram called PRUSHI. To do this you must first prototype the subprogram:
Së pari të krijojë një nën-programore quajtur PRUSHI. Për ta bërë këtë ju duhet së pari të prototip e nën-programore:
int PRUSHI(int a, int b, int c, int d, bool mode); //mode determines whether to Σ or Π
Then you must define the subprogram. For a simple program this is usually done after writing main():
Pastaj ju duhet të përcaktojë nën-programore. Për një program të thjeshtë kjo është bërë zakonisht pas shkruar main():
1
2
3
4
int PRUSHI(int a, int b, int c, int d, bool mode)
{
   //code for PRUSHI goes here
}


The reason we add the "mode" argument is to determine whether PRUSHI should act as Σ or Π. So all you need to do to complete the assignment is combine the code you have written for Sum and Product into PRUSHI, using the value of "mode" to determine whether to use the Shuma or Prodhimi code.
Arsyeja që ne të shtoni argumentin "mode" është për të përcaktuar nëse Prushi duhet të veprojë si Σ ose Π. Pra, të gjithë ju duhet të bëni për të përfunduar detyrën është të kombinuar kodin që keni shkruar për Sum dhe Produkt në PRUSHI, duke përdorur vlerën e "mode" për të përcaktuar nëse do të përdorim Shuma ose kod Prodhimi.

The final code for PRUSHI will look something like this:
Kodi përfundimtar për PRUSHI do të dukej diçka si kjo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int PRUSHI(int a, int b, int c, int d, bool mode)
{
   int value;
   if (mode)
   {
       //Shuma code determines "value"
      return value;
   }
   else
   {
      //Prodhimi code determines "value"
      return value;
   }
}


Then you rewrite the code in main(). I'll leave that to you.
Pastaj ju rishkruaj kodin në main(). Unë do të iki që për ju.
@heebleworp

i dont now how to do this homework im very confuse , can you help me



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
using namespace std;
int PRUSHI(int a, int b, int c, int d, bool mode)
double Shuma(int a,int b,int c, int d);
double Prodhimi(int a,int b,int c, int d);
int main ()
	int PRUSHI(int a, int b, int c, int d, bool mode)
{
	int n;
	int PRUSHI;
	cout<<"jepe vleren e n:";
	cin>>n;
	PRUSHI=Shuma(2,n,1,3)+2*Prodhimi(0,n-1,1,1)+3*Shuma(1,6,1,2)+Prodhimi(4,n+1,1,3);

	cout<< "Vlera = " << PRUSHI;
	cout<<endl;
	system("pause");
	return 0;
}
int PRUSHI(int a, int b, int c, int d, bool mode)
{
   int Shuma;
   if (mode)
   {
       int i;
	double S;
	S=0;
	for(i=a;i<=b;i++)
	{
		S=S+(c*i+d);
	}
	return S;
   }
   else
   {
      int i;
	double P;
	P=1;
	for(i=a;i<=b;i++)
	{
		P=P*(c*i+d);
	}
	return P;
   }
}
@heebleworp

can you help me or someone else
I have not tested this, but you seem to be very close now, this would be the final step.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
using namespace std;
double PRUSHI(int a, int b, int c, int d, bool mode);

int main ()
{
	int n;
	double PRUSHI_RESULT;
	cout<<"jepe vleren e n:";
	cin>>n;
	PRUSHI_RESULT=PRUSHI(2,n,1,3,true)+2*PRUSHI(0,n-1,1,1,false)+3*PRUSHI(1,6,1,2,true)+PRUSHI(4,n+1,1,3,false);

	cout<< "Vlera = " << PRUSHI_RESULT;
	cout<<endl;
	system("pause");
	return 0;
}

double PRUSHI(int a, int b, int c, int d, bool mode)
{
   if (mode)
   {
       int i;
	double S;
	S=0;
	for(i=a;i<=b;i++)
	{
		S=S+(c*i+d);
	}
	return S;
   }
   else
   {
      int i;
	double P;
	P=1;
	for(i=a;i<=b;i++)
	{
		P=P*(c*i+d);
	}
	return P;
   }
}
Last edited on
Topic archived. No new replies allowed.