Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. prototyped function not called (was a variable definition intended?)
  2.  
  3. Comp_Num Comp_Num::operator- (Comp_Num &c1, Comp_Num &c2);
  4.  
  5. c:usersandrewdocumentsvisual studio 2012projectsandrew_spiteri_hw5complex_number.h(226): warning C4930: 'Comp_Num operator +(Comp_Num &,Comp_Num &)': prototyped function not called (was a variable definition intended?)
  6. c:usersandrewdocumentsvisual studio 2012projectsandrew_spiteri_hw5complex_number.h(228): warning C4930: 'Comp_Num operator -(Comp_Num &,Comp_Num &)': prototyped function not called (was a variable definition intended?)
  7. c:usersandrewdocumentsvisual studio 2012projectsandrew_spiteri_hw5complex_number.h(230): warning C4930: 'Comp_Num operator *(Comp_Num &,Comp_Num &)': prototyped function not called (was a variable definition intended?)
  8. Complex_Number.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > Comp_Num::imag1" (?imag1@Comp_Num@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
  9. Complex_Number.obj : error LNK2001: unresolved external symbol "public: static double Comp_Num::r1_final" (?r1_final@Comp_Num@@2NA)
  10. Complex_Number.obj : error LNK2001: unresolved external symbol "public: static double Comp_Num::r2_final" (?r2_final@Comp_Num@@2NA)
  11.  
  12. #include <iostream>
  13. #include <String>
  14. #include <vector>
  15. #include <sstream>
  16.  
  17. using namespace std;
  18.  
  19. #ifndef Comp_Num
  20. class Comp_Num
  21. {
  22. private:
  23. std::vector <double> real;
  24. std::vector <double> imag;
  25. double real_in, real_in1, real_in2;
  26. static double r1_final, r2_final;
  27. std::string imag_in;
  28. static std::string imag1;
  29. public:
  30. Comp_Num();
  31. Comp_Num(double real_num, std::string img_num);
  32.  
  33. static std::vector <std::string> get_input();
  34. static std::vector <std::string> get_real(std::vector <string> complexnum1);
  35. static std::vector <std::string> get_imag(std::vector <std::string> complexnum2);
  36. static void display(std::vector <std::string> display1);
  37. static void display2(std::vector <double> display3);
  38. static std::vector <std::string> set_compnum();
  39. static std::vector <std::string> comp2real(std::vector <std::string> c2r);
  40. static std::vector <double> real2double (std::vector<std::string> r2d);
  41. static double double_const(std::vector<double> dc);
  42. friend Comp_Num operator +(const Comp_Num &c3, const Comp_Num &c4);
  43. friend Comp_Num operator -(const Comp_Num &c3, const Comp_Num &c4);
  44. friend Comp_Num operator *(const Comp_Num &c3, const Comp_Num &c4);
  45. static void operation();
  46. ~Comp_Num();
  47. /*
  48. double Comp_Num::operator+ (double add_num);
  49. double Comp_Num::operator- (double sub_num);
  50. double Comp_Num::operator* (double mul_num);
  51. double Comp_Num::operator/ (double div_num);
  52. */
  53. };
  54. #endif !Comp_Num
  55.  
  56. Comp_Num::Comp_Num()
  57. {
  58. double real_in = 1;
  59. string imag_in = "i";
  60. };
  61.  
  62. Comp_Num::Comp_Num(double real_num, std::string imag_num)
  63. {
  64. double real_in = real_num;
  65. string imag_in = imag_num;
  66. };
  67.  
  68. std::vector <string> Comp_Num::set_compnum()
  69. {
  70. std::vector <string>set_num= Comp_Num::get_input();
  71. std::vector<string>comp1=Comp_Num::get_real(set_num);
  72. std::vector <string>comp2= Comp_Num::get_imag(set_num);
  73. std::vector <string>cmp2rl_fin = Comp_Num::comp2real(comp2);
  74. std::vector<double>finale = Comp_Num::real2double(cmp2rl_fin);
  75. Comp_Num::double_const (finale);
  76. imag1 = "i";
  77. Comp_Num *c1 = new Comp_Num(r1_final, imag1);
  78. Comp_Num *c2 = new Comp_Num(r2_final, imag1);
  79.  
  80. Comp_Num::display(comp2);
  81. std::system("pause");
  82. return(comp2);
  83. };
  84.  
  85. std::vector <string> Comp_Num::get_input()
  86. {
  87. std::string usr_input, input1;
  88. std::vector <string> complex;
  89. std::cout<<"Enter 2 imaginary numbers you would like to perform your operation on.n";
  90. std::getline(std::cin, usr_input);
  91. std::istringstream input(usr_input);
  92. while(input >> input1)
  93. {
  94. complex.push_back(input1);
  95. }
  96. std::cout<<'n';
  97. return (complex);
  98. };
  99.  
  100. std::vector <string> Comp_Num::get_imag(std::vector <string> complexnum2)
  101. {
  102. std::vector <string> imag1;
  103. for(unsigned int i = 0; i < complexnum2.size(); ++i)
  104. {
  105. std::string str2 = "";
  106. std::vector<char> char1(complexnum2[i].begin(), complexnum2[i].end());
  107. for(unsigned int r = 0; r < char1.size(); ++r)
  108. {
  109. if(char1[r] >= '0' && char1[r] <= '9' || char1[r] == '-' || char1[r] == '.' || char1[r] == 'i')
  110. {
  111. str2 += char1[r];
  112. if(char1[r] == 'i')
  113. {
  114. imag1.push_back(str2);
  115. continue;
  116. }
  117. }
  118. }
  119. }
  120. return(imag1);
  121. };
  122.  
  123. std::vector <string> Comp_Num::get_real(std::vector <string> complexnum1)
  124. {
  125. std::vector <string> real1;
  126. for(unsigned int i = 0; i < complexnum1.size(); ++i)
  127. {
  128. std::string str2 = "";
  129. std::vector<char> char1(complexnum1[i].begin(), complexnum1[i].end());
  130. for(unsigned int r = 0; r < char1.size(); ++r)
  131. {
  132. if(char1[r] >= '0' && char1[r] <= '9' || char1[r] == '-' || char1[r] == '.' || char1[r] == 'i')
  133. {
  134. str2 += char1[r];
  135. if(char1[r] == 'i')
  136. {
  137. str2="";
  138. break;
  139. }
  140. }
  141. }
  142. real1.push_back(str2);
  143. }
  144. return(real1);
  145. };
  146.  
  147. void Comp_Num::display (std::vector <string> display1)
  148. {
  149. unsigned int i = 0;
  150. while (i < display1.size())
  151. {
  152. std::cout<<display1[i]<<" ";
  153. i++;
  154. }
  155. std::cout<<std::endl;
  156. };
  157.  
  158. void Comp_Num::display2 (std::vector <double> display3)
  159. {
  160. unsigned int i = 0;
  161. while (i < display3.size())
  162. {
  163. std::cout<<display3[i]<<" ";
  164. i++;
  165. }
  166. std::cout<<std::endl;
  167. };
  168.  
  169. std::vector <string> Comp_Num::comp2real(std::vector <string> c2r)
  170. {
  171. std::vector <string> real2;
  172. for(unsigned int i = 0; i < c2r.size(); ++i)
  173. {
  174. std::string str2 = "";
  175. std::vector<char> char1(c2r[i].begin(), c2r[i].end());
  176. for(unsigned int r = 0; r < char1.size(); ++r)
  177. {
  178. if(char1[r] >= '0' && char1[r] <= '9' || char1[r] == '-' || char1[r] == '.')
  179. {
  180. str2 += char1[r];
  181. }
  182. }
  183. real2.push_back(str2);
  184. }
  185. return(real2);
  186. }
  187.  
  188. std::vector<double> Comp_Num::real2double (std::vector<string> r2d)
  189. {
  190. double y;
  191. std::vector<double> final_r2d;
  192. std::string str, str2;
  193. std::vector<string>str3;
  194. for(unsigned int i = 0; i < r2d.size(); ++i)
  195. {
  196. std::vector<char> ch(r2d[i].begin(), r2d[i].end());
  197. for(unsigned int r = 0; r < ch.size(); ++r)
  198. {
  199. if(ch[r] >= '0' && ch[r] <= '9' || ch[r] == '-' || ch[r] == '.')
  200. {
  201. str2 += ch[r];
  202. }
  203. }
  204. str3.push_back(str2);
  205. str2="";
  206. }
  207. for(unsigned int r = 0; r < str3.size(); r++)
  208. {
  209. str = str3[r];
  210. std::istringstream to_double(str);
  211. while(to_double >> y)
  212. {
  213. final_r2d.push_back(y);
  214. }
  215. }
  216. return(final_r2d);
  217. };
  218.  
  219. double Comp_Num::double_const(std::vector<double>dc)
  220. {
  221. r1_final=dc[0];
  222. r2_final=dc[1];
  223. return(0);
  224. };
  225.  
  226. void Comp_Num::operation()
  227. {
  228. std::string operate;
  229. std::cout<<"What operation would you like perform on the numbers?n";
  230. std::cout<<"You may choose between addition, subtraction, and multiplication.n";
  231. std::getline(cin,operate);
  232. if(operate == "addition")
  233. Comp_Num operator+ (Comp_Num &c1, Comp_Num &c2);
  234. else if (operate == "subtraction")
  235. Comp_Num operator- (Comp_Num &c1, Comp_Num &c2);
  236. else if (operate == "multiplication")
  237. Comp_Num operator* (Comp_Num &c1, Comp_Num &c2);
  238. else
  239. {
  240. cout<<"This is not a valid entry. Please start over."<<std::endl;
  241. std::exit(0);
  242. }
  243. };
  244.  
  245. Comp_Num operator +(const Comp_Num &c3, const Comp_Num &c4)
  246. {
  247. std::string output,imaginary = "i";
  248. double final_real = c3.real_in + c4.real_in;
  249. std::cout<<"The difference of your imaginary numbers is "<<final_real<<imaginary<<std::endl;
  250. return(c3);
  251. };
  252.  
  253. Comp_Num operator -(const Comp_Num &c3, const Comp_Num &c4)
  254. {
  255. std::string output,imaginary = "i";
  256. double final_real = c3.real_in - c4.real_in;
  257. std::cout<<"The difference of your imaginary numbers is "<<final_real<<imaginary<<std::endl;
  258. return(c3);
  259. };
  260.  
  261. Comp_Num operator *(const Comp_Num &c3, const Comp_Num &c4)
  262. {
  263. std::string output,imaginary = "i";
  264. double final_real = c3.real_in * c4.real_in;
  265. final_real *= -1;
  266. std::cout<<"The difference of your imaginary numbers is "<<final_real<<std::endl;
  267. return(c3);
  268. };
  269.  
  270. if(operate == "addition")
  271. Comp_Num operator+ (Comp_Num &c1, Comp_Num &c2);
  272. else if (operate == "subtraction")
  273. Comp_Num operator- (Comp_Num &c1, Comp_Num &c2);
  274. else if (operate == "multiplication")
  275. Comp_Num operator* (Comp_Num &c1, Comp_Num &c2);
  276.  
  277. Comp_num c1, c2, c3; // get these from somewhere.
  278. if(operate == "addition")
  279. c3 = c1 + c2;
  280. else if (operate == "subtraction")
  281. c3 = c1 - c2;
  282. else if (operate == "multiplication")
  283. c3 = c1 * c2;
  284.  
  285. double Comp_Num::r1_final = 0;
  286.  
  287. Comp_Num cm
  288. if(operate == "addition")
  289. cm = c1 + c2;
  290. else if (operate == "subtraction")
  291. cm = c1 - c2;
  292. else if (operate == "multiplication")
  293. cm = c1 * c2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement