Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 KB | None | 0 0
  1. Answer No.1: Code<
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. double c,f;
  7. cout<<"\tCelcius\t\tFarenheit\n";
  8. for(c=10;c<=18;c+=4)
  9. {
  10. f=((c*9)/5)+32;
  11. cout<<"\t"<<c<<"\t\t"<<f<<endl;
  12. }
  13. return 0;
  14. }
  15. Output:
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. Answer No:2.
  25. #include<bits/stdc++.h>
  26. using namespace std;
  27. int main()
  28. { string a="`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
  29. string s;
  30. getline(cin,s);
  31. for(int i=0; i<=s.size(); i++)
  32. { for(int j=0; j<=a.size()-1; j++)
  33. { if(s[i]==a[j])
  34. { cout<<a[j-2]; break; }
  35. else if(s[i]==' ')
  36. { cout<<" ";
  37. break; } } }
  38. cout<<endl;
  39. }
  40. Output:
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. Answer No: 3.Convert into number:
  49. #include <iostream>
  50. #include <vector> // std::vector
  51. #include <algorithm> // std::reverse
  52.  
  53. const std::vector<std::string> first_twenty_vocabular = {
  54. "zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ",
  55. "eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ",
  56. "nineteen " };
  57. const std::vector<std::string> magnitude_vocabular = {
  58. "hundred ","thousand ","million ", "billion "};
  59. const std::vector<std::string> decine_vocabular = {
  60. "twenty ", "thirty ", "fourty ", "fifty ", "sixty ", "seventy ","eighty ","ninety "};
  61. std::string Stringer(std::vector<int> src);
  62. std::string MagnitudeSplitter(std::vector<int> src);
  63. std::vector<int> VectorSplitter(std::vector<int> &V);
  64. std::string units(std::vector<int> src);
  65. std::string decine(std::vector<int> src);
  66. )
  67. std::string hundreds(std::vector<int> src);
  68. void FlipVector(std::vector<int>& V) {
  69. std::reverse(V.begin(), V.end());
  70. }
  71. void PrintVector(std::vector<int> v) {
  72. int len = v.size();
  73. for (int i = 0; i < len; ++i) { std::cout << v[i];}
  74. std::cout << std::endl;
  75. }
  76.  
  77. std::vector<int> Splitter(int src_num) {
  78. std::vector<int> v_Digits;
  79. if (src_num == 0) {
  80. v_Digits.push_back(0);
  81. return v_Digits;
  82. }
  83. else {
  84. while(src_num >= 10) {
  85. v_Digits.push_back(src_num%10);
  86. src_num /= 10;
  87. }
  88. v_Digits.push_back(src_num);
  89. return v_Digits;
  90. }
  91. }
  92. std::string units(std::vector<int> src) {
  93. std::string uni_str = first_twenty_vocabular[src[0]];
  94. return uni_str;
  95. }
  96.  
  97. std::string decine(std::vector<int> src) {
  98. std::string dec_str = "";
  99. if (src[0] == 0) {
  100. if (src[1] == 0) { return dec_str; }
  101. else {
  102. dec_str.append(first_twenty_vocabular[src[1]]);
  103. return dec_str;
  104. }
  105. }
  106. else if (src[0] == 1) {
  107. dec_str.append(first_twenty_vocabular[10+src[1]]);
  108. return dec_str;
  109. }
  110. else {
  111. dec_str.append(decine_vocabular[src[0]-2]);
  112. if(src[1] == 0) { return dec_str; }
  113. else {
  114. dec_str.append(first_twenty_vocabular[src[1]]);
  115. return dec_str;
  116. }
  117. }
  118. }
  119.  
  120. std::string hundreds(std::vector<int> src) {
  121. std::string hundred_string = "";
  122.  
  123. if(src[0] == 0) {
  124. std::vector<int> dec_vec= {src[1],src[2]};
  125. std::string dec_str = decine(dec_vec);
  126. hundred_string.append(dec_str);
  127. return hundred_string;
  128. }
  129. else {
  130. hundred_string.append(first_twenty_vocabular[src[0]]);
  131. hundred_string.append("hundred ");
  132. std::vector<int> dec_vec= {src[1],src[2]};
  133. std::string dec_str = decine(dec_vec);
  134. hundred_string.append(dec_str);
  135. return hundred_string;
  136. }
  137. }
  138.  
  139.  
  140. std::string Stringer(std::vector<int> src) {
  141. std::string num_string = "";
  142. int len = src.size();
  143. if( src[0] < 0 ) {
  144. num_string.append("minus ");
  145. for (int i = 0; i < len; ++i) { src[i] = -i; }
  146. }
  147.  
  148. if (len == 1) {
  149. std::string add = units(src);
  150. num_string.append(add);
  151. } else if (len == 2) {
  152. std::string add = decine(src);
  153. num_string.append(add);
  154. } else if (len == 3) {
  155. std::string add = hundreds(src);
  156. num_string.append(add);
  157. } else {
  158. return MagnitudeSplitter(src);
  159. }
  160. return num_string;
  161. }
  162.  
  163. std::vector<int> VectorSplitter(std::vector<int> &V){
  164. std::vector<int> first_digits;
  165. int len = V.size();
  166. if (len%3 == 0) {
  167. for(int i = 0; i < 3; ++i) {
  168. first_digits.push_back(V[0]);
  169. FlipVector(V);
  170. V.pop_back();
  171. FlipVector(V);
  172. }
  173.  
  174. } else {
  175. for( int i = 0; i < (len-(3*(len/3))); ++i) {
  176. first_digits.push_back(V[0]);
  177. FlipVector(V);
  178. V.pop_back();
  179. FlipVector(V);
  180. }
  181. }
  182.  
  183. return first_digits;
  184. }
  185.  
  186.  
  187. std::string MagnitudeSplitter(std::vector<int> src) {
  188. int len = src.size();
  189. std::string tot_str = "";
  190.  
  191. if (len == 3) {
  192. return Stringer(src);
  193. } else {
  194. std::vector<int> first_digits = VectorSplitter(src);
  195. int new_len = first_digits.size();
  196. std::string add = Stringer(first_digits);
  197.  
  198. int sum_values = 0; // To know if there are only zeroes.
  199. for ( int i = 0; i < new_len; ++i) {
  200. sum_values += first_digits[i];
  201. }
  202. tot_str.append(add);
  203. if (sum_values) { tot_str.append(magnitude_vocabular[(len-1)/3]);
  204. }
  205. std::string return_str = Stringer(src);
  206. tot_str.append(return_str);
  207. }
  208. return tot_str;
  209. }
  210. int main() {
  211. std::cout << "insert your number: "; int x; std::cin >> x;
  212. std::vector<int> v_result = Splitter(x);
  213. FlipVector(v_result);
  214. PrintVector(v_result);
  215. std::cout << Stringer(v_result) << std::endl;
  216. }
  217. Output:
  218.  
  219.  
  220.  
  221. Answer No:4.
  222. #include<iostream>
  223. using namespace std;
  224. class Area
  225. {private:
  226. int a,b;
  227. float c;
  228. public:
  229. void triangle()
  230. {cout <<"area of triangle is: " ;
  231. c=0.5*a*b;
  232. cout<<c <<endl;
  233. }
  234. void rectangle()
  235. {cout<<"area of rectangle is: "<<a*b<<endl;
  236. }
  237.  
  238. Area(int x,int y)
  239. {
  240. a=x;
  241. b=y;
  242. }
  243. Area(int x)
  244. {
  245. a=x;
  246. }
  247. };
  248. int main()
  249. {Area obj(4,6);
  250. Area obj1=Area(2,3);
  251. Area obj2=8;
  252. obj.triangle();
  253. obj1.rectangle();
  254. return 0;
  255. }
  256. Output:
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. Answer No:5.
  271.  
  272. #include <iostream>
  273.  
  274. class Person {
  275. protected:
  276. void breathe() {
  277. std::cout << "I'm in Engineering faculty." << std::endl;
  278. }
  279. };
  280.  
  281. class Faculty : protected Person {
  282. protected:
  283. void breathe() {
  284. std::cout << "In ICT department." << std::endl;
  285. }
  286. };
  287.  
  288. class Student : protected Person {
  289. protected:
  290. void crawl() {
  291. std::cout << "I'm Shanto." << std::endl;
  292. }
  293. };
  294.  
  295. class Shanto : protected Faculty, protected Student {
  296. public:
  297. void breathe() {
  298. std::cout << "I'm Shanto." << std::endl;
  299. }
  300.  
  301. void c() {
  302. std::cout << "My ID:IT-17027" << std::endl;
  303. }
  304. };
  305.  
  306. int main() {
  307. Shanto shan;
  308.  
  309. shan.breathe();
  310. shan.c();
  311.  
  312. return 0;
  313. }
  314. Output:
  315.  
  316.  
  317. Answer No:6.
  318. ~Early binding
  319. #include <iostream>
  320. using namespace std;
  321. class Animals
  322. {
  323. public:
  324. void walk()
  325. {
  326. cout << "This is Early Binding" << endl;
  327. }};
  328. class Dogs : public Animals
  329. {
  330. public:
  331. void walk()
  332. {
  333. cout << "Dogs walk" << endl;
  334. }};
  335. int main()
  336. {
  337. Animals *a;
  338. Dogs d;
  339. a= &d;
  340. a -> walk(); // early binding
  341. return 0;
  342. }
  343. Output:
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351. ~~Late Binding
  352. #include <iostream>
  353.  
  354. using namespace std;
  355.  
  356. class Animals
  357. {
  358. public:
  359. virtual void sound()
  360. {
  361. cout << "This is Late binding" << endl;
  362. }
  363. };
  364.  
  365. class cat : public Animals
  366. {
  367. public:
  368. void sound()
  369. {
  370. cout << "Mio mio mio miaaaao" << endl;
  371. }
  372. };
  373.  
  374. int main()
  375. {
  376. Animals *a;
  377. cat d;
  378. a= &d;
  379. a -> sound();
  380. return 0;
  381. }
  382. Output:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement