Advertisement
Guest User

Untitled

a guest
May 30th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. List
  2. Looking at the program “Salesperson’s list”, create another
  3. program that will do the following:
  4.  
  5. 1. Ask user to input 2 different lists of salespersons.
  6.  
  7. 2. Concatenate two lists into one.
  8.  
  9.  
  10.  
  11. In order to do that you will have to create second list
  12. (define another pointer to the head and another pointer to the current), and
  13. write function that will add one list to the other. This function has to
  14. redefine pointer of the last element of the first list, so that it will point
  15. to the first element of the second list.
  16.  
  17. Print new list in the form of the report.
  18.  
  19.  
  20.  
  21.  
  22.  
  23. Salesperson’s list
  24.  
  25.  
  26. include
  27. <iostream>
  28.  
  29. #
  30. include <string>
  31.  
  32.  
  33.  
  34. using
  35. namespace std;
  36.  
  37.  
  38.  
  39. struct
  40. SalesPerson {
  41.  
  42.  
  43.  
  44. SalesPerson *next;
  45.  
  46. string name;
  47.  
  48. int level;
  49.  
  50. float comission;
  51.  
  52. float amount;
  53.  
  54.  
  55.  
  56. void Print()
  57.  
  58. {
  59.  
  60. cout.width(10);
  61.  
  62. cout << name;
  63.  
  64. cout.width(20);
  65.  
  66. cout << level;
  67.  
  68. cout.width(20);
  69.  
  70. cout << amount;
  71.  
  72. cout.width(20);
  73.  
  74. cout << comission <<
  75. endl << endl;
  76.  
  77. }
  78.  
  79. };
  80.  
  81.  
  82.  
  83. struct SalesPerson* Head = NULL;
  84.  
  85. struct SalesPerson* Current =
  86. NULL;
  87.  
  88.  
  89.  
  90. void Add(struct SalesPerson);
  91.  
  92.  
  93.  
  94. void
  95. main()
  96.  
  97. {
  98.  
  99. struct SalesPerson S;
  100.  
  101. char answer[10] =
  102. "Yes";
  103.  
  104.  
  105.  
  106. do
  107.  
  108. {
  109.  
  110. cout << "\nEnter
  111. sales person name: ";
  112.  
  113. cin >> S.name;
  114.  
  115. cout << "\nEnter
  116. sales amount: ";
  117.  
  118. cin >> S.amount;
  119.  
  120. cout << "\nEnter
  121. level of comisiions: ";
  122.  
  123. cin >> S.level;
  124.  
  125. cout << endl;
  126.  
  127. Add(S);
  128.  
  129. cout << "Do you want
  130. to enter another? (Yes/No): ";
  131.  
  132. cin >> answer;
  133.  
  134. } while (strcmp(answer,
  135. "No") != 0);
  136.  
  137.  
  138.  
  139. cout.width(10);
  140.  
  141. cout << "Name";
  142.  
  143. cout.width(20);
  144.  
  145. cout << "Comission
  146. level";
  147.  
  148. cout.width(20);
  149.  
  150. cout << "Amount of sales";
  151.  
  152. cout.width(20);
  153.  
  154. cout <<
  155. "Comission" << endl << endl;
  156.  
  157.  
  158.  
  159. for(Current = Head; Current
  160. -> next != NULL; Current = Current -> next)
  161.  
  162. Current ->
  163. Print();
  164.  
  165. Current -> Print();
  166.  
  167. }
  168.  
  169.  
  170.  
  171. void
  172. Add(struct SalesPerson a)
  173.  
  174. {
  175.  
  176. if (Current == NULL)
  177.  
  178. {
  179.  
  180. Current = new(SalesPerson);
  181.  
  182. Head = Current;
  183.  
  184. Current ->
  185. next = NULL;
  186.  
  187. }
  188.  
  189. else
  190.  
  191. {
  192.  
  193. Current ->
  194. next = new(SalesPerson);
  195.  
  196. Current =
  197. Current -> next;
  198.  
  199. Current ->
  200. next = NULL;
  201.  
  202. }
  203.  
  204.  
  205.  
  206. Current -> name = a.name;
  207.  
  208. Current -> level = a.level;
  209.  
  210. Current -> amount = a.amount;
  211.  
  212. if(a.level == 1) Current ->
  213. comission = a.amount * 0.06;
  214.  
  215. else Current
  216. -> comission = a.amount * 0.08;
  217.  
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement