AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Polynomial function + small console program - C++

Go down

Polynomial function + small console program - C++

Post by Lucaci Andrei on Mon Mar 12, 2012 2:28 am

Detailed you will see the 4 modules.
avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

main.cpp

Post by Lucaci Andrei on Mon Mar 12, 2012 2:28 am

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
* lab3.cpp
* lab3.cpp is licensed under GNU GENERAL PUBLIC LICENSE
* Created on: Mar 12, 2012
* Author: sin
*/
#include"main.h"
array read()
/*
* Holds the information of the array.
*/
{
array A={0,2,3,4,5,1};
return A;
}
void help()
/*
* Prints out the help message.
*/
{
cout<<"Welcome to Polynomial help.\nHere I will explain the mechanism\nbehind this little program.\nYou are required to enter a value, which\nwill be hold as an argument of the current function\nof the polynomial. This function will\ncompute the polynomial function: \n2*x^0+3*x^1+4*x^2+5*x^3+1*x^4\nwhere x takes the value you have inserted.\n";
}

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

main.h

Post by Lucaci Andrei on Mon Mar 12, 2012 2:29 am

 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
/*
* lab3.h
* lab3.h is licensed under GNU GENERAL PUBLIC LICENSE
* Created on: Mar 12, 2012
* Author: sin
*/
/*
* Making the appropriate imports.
*/
#ifndef LAB3_H_
#define LAB3_H_
#include<iostream>
using namespace std;
/*
* Declaring the structure of the array.
*/
struct array{
int size;
int a[6];
};

array read();
/*
* This function, of the type struct array
* will hold the coefficients of the polynomial.
*/
void help();
/*
* Will print out a help message about the program.
*/

#endif /* LAB3_H_ */

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

run.cpp

Post by Lucaci Andrei on Mon Mar 12, 2012 2:30 am

 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* run.cpp
* run.cpp is licensed under GNU GENERAL PUBLIC LICENSE
* Created on: Mar 12, 2012
* Author: sin
*/
#include"main.h"
#include"run.h"

void compute()
/*
* Will compute the polynomial
* function accordingly to the
* given data.
*/
{
array sh;
sh=read();
float x, rez=0;
cout<<"This will compute the polynomial as a sum: \n2*x^0+3*x^1+4*x^2+5*x^3+1*x^4\nValue of x= ";
cin>>x;
for (int i=0;i<5;i++){
rez=rez+sh.a[i]*pow(x,i);
}
cout<<"\nThe value of the polynomial is "<<rez<<"."<<endl<<endl;

}

void invalid()
/*
* Will print out a message.
* It is used in the console, in the ui
* when a wrong command is given.
*/
{
string l="-";
for (int y=0;y<=60;y++){
cout<<l;
}
cout<<endl;
cout<<" Invalid command\n";
for (int y=0;y<=60;y++){
cout<<l;
}
cout<<endl;
}

void menu()
/*
* Will print out the menu. It is called
* from the UI function.
*/
{
cout<<"Welcome to Polynomial\nPlease, choose an option: \n 1. Run polynomial.\n 2. Help.\n Type 'exit' to quit the program.\n";

}

int main()
/*
* The main function which holds the
* UI of this program.
*/
{
string answer;
menu();
int wr=0;
for (;Wink{
cout<<"\n\\\\: ";
cin>>answer;
cout<<endl;
if (answer=="1" or answer=="1."){
compute();
}
else if (answer=="2" or answer=="2."){
help();
}
else if (answer=="exit" or answer=="q"){
exit(0);
}
else if (answer=="menu"){
menu();
}
else if (answer=="hidden"){
cout<<"1. wr - Number of invalid commands.\n2. q - Quick exit.\n";
}
else if (answer=="wr"){
cout<<"Number of invalid commands: "<<wr<<endl;
}
else {
invalid();
wr+=1;
}
}
}

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

run.h

Post by Lucaci Andrei on Mon Mar 12, 2012 2:30 am

 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
/*
* run.h
* run.h is licensed under GNU GENERAL PUBLIC LICENSE
* Created on: Mar 12, 2012
* Author: sin
*/

/*
* Making the appropriate imports.
*/
#ifndef RUN_H_
#define RUN_H_
#include<iostream>
#include<math.h>
#include"main.h"
#include<string>
#include<string.h>
using namespace std;

void compute();
/*
* This will compute the polynomial function.
*/
void menu();
/*
* This will print the menu.
*/
void invalid();
/*
* This will print out error message.
*/
int main();
/*
* Holds the UI of the function.
*/

#endif /* RUN_H_ */

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Re: Polynomial function + small console program - C++

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum