upsidedown

oops 4: a, b,c,d

Feb 24th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.97 KB | None | 0 0
  1. // friend func.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include<iostream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. class abc;
  11.  
  12. class xyz
  13. {
  14.     int a;
  15. public:
  16.     void enter()
  17.     {
  18.         cout<<"enter the value";
  19.         cin>>a;
  20.     }
  21.  
  22.     friend  void swap(abc, xyz);
  23. };
  24.  
  25.  
  26. class abc
  27. {
  28.     int a;
  29. public:
  30.     void enter()
  31.     {
  32.         cout<<"enter the value";
  33.         cin>>a;
  34.     }
  35.  
  36.     friend  void swap(abc, xyz);
  37. };
  38.  
  39.  
  40.  
  41. void swap(abc ab, xyz xy)
  42. {
  43.     cout<<"\nabc contains"<<ab.a;
  44.     cout<<"\nxyz contains"<<xy.a;
  45.  
  46.     int temp;
  47.     temp=ab.a;
  48.     ab.a=xy.a;
  49.     xy.a=temp;
  50.  
  51.     cout<<"\n\nafter swapping\n";
  52.     cout<<"\nabc contains"<<ab.a;
  53.     cout<<"\nxyz contains"<<xy.a<<endl;
  54.  
  55. }
  56.  
  57.  
  58.  
  59. int _tmain(int argc, _TCHAR* argv[])
  60. {
  61.     abc a;
  62.     xyz x;
  63.      a.enter();
  64.      x.enter();
  65.      swap(a,x);
  66.      system("pause");
  67.      
  68.     return 0;
  69. }
  70.  
  71. /*
  72. enter the value8
  73. enter the value9
  74.  
  75. abc contains8
  76. xyz contains9
  77.  
  78. after swapping
  79.  
  80. abc contains9
  81. xyz contains8
  82. Press any key to continue . . .
  83. */
  84.  
  85.  
  86.  
  87.  
  88.  
  89. //fourth program
  90. // friend func.cpp : Defines the entry point for the console application.
  91.  
  92.  
  93. #include "stdafx.h"
  94. #include<iostream>
  95.  
  96. using namespace std;
  97.  
  98.  
  99. class professor;
  100.  
  101. class bank
  102. {
  103.     double monthly;
  104.     char gender;
  105. public:
  106.     void enter()
  107.     {
  108.         cout<<"enter the gender for bank class";
  109.         cin>>gender;
  110.         cout<<"Enter monthly salary";
  111.         cin>>monthly;
  112.  
  113.     }
  114.  
  115.     friend  void calc(bank, professor);
  116. };
  117.  
  118.  
  119. class professor
  120. {
  121.    
  122.     double monthly;
  123.     char gender;
  124. public:
  125.     void enter()
  126.     {
  127.         cout<<"\nenter the gender for bank class";
  128.         cin>>gender;
  129.         cout<<"Enter monthly salary";
  130.         cin>>monthly;
  131.  
  132.     }
  133.  
  134.     friend  void calc(bank, professor);
  135. };
  136.  
  137.  
  138.  
  139. void calc(bank b, professor p)
  140. {
  141.    
  142.     double gross_bank=b.monthly*12;
  143.     double gross_prof=p.monthly*12;
  144.  
  145.     double net_b, net_p;
  146. //handle bank class
  147.     if(b.gender=='f' || b.gender=='F')
  148.     {
  149.         net_b=gross_bank-190000;
  150.     }
  151.     else
  152.     {
  153.             net_b=gross_bank-180000;
  154.     }
  155.  
  156.     if(net_b>1000000)
  157.         cout<<"\nIncome tax for bank class is "<<net_b*0.3;
  158.     else if(net_b>500000)
  159.         cout<<"\nIncome tax for bank class is "<<net_b*0.2;
  160.     else if(net_b>300000)
  161.         cout<<"\nIncome tax for bank class is "<<net_b*0.1;
  162.     else
  163.         cout<<"\nfor bank class, NO tax ";
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.     //handle prof class
  174.     if(p.gender=='f' || p.gender=='F')
  175.     {
  176.         net_p=gross_prof-190000;
  177.     }
  178.     else
  179.     {
  180.             net_p=gross_prof-180000;
  181.     }
  182.  
  183.         if(b.gender=='f' || b.gender=='F')
  184.     {
  185.         net_b=gross_bank-190000;
  186.     }
  187.     else
  188.     {
  189.             net_b=gross_bank-180000;
  190.     }
  191.  
  192.     if(net_p>1000000)
  193.         cout<<"\nIncome tax for professor class is "<<net_p*0.3;
  194.     else if(net_p>500000)
  195.         cout<<"\nIncome tax for professor class is "<<net_p*0.2;
  196.     else if(net_p>300000)
  197.         cout<<"\nIncome tax for professor class is "<<net_p*0.1;
  198.     else
  199.         cout<<"For professor class: no tax";
  200. }
  201.  
  202.  
  203.  
  204. int _tmain(int argc, _TCHAR* argv[])
  205. {
  206.     bank a;
  207.     professor x;
  208.      a.enter();
  209.      x.enter();
  210.      calc(a,x);
  211.      system("pause");
  212.      
  213.     return 0;
  214. }
  215.  
  216.  
  217.  
  218. /*
  219.  
  220. enter the gender for bank class f
  221. Enter monthly salary40000
  222.  
  223. enter the gender for bank class m
  224. Enter monthly salary60000
  225.  
  226. for bank class, NO tax
  227. Income tax for professor class is 108000
  228. Press any key to continue . . .
  229. */
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245. // friend func.cpp : Defines the entry point for the console application.
  246. //
  247.  
  248. #include "stdafx.h"
  249. #include<iostream>
  250.  
  251. using namespace std;
  252.  
  253.  
  254. class abc;
  255.  
  256. class xyz
  257. {
  258.     int a;
  259. public:
  260.     void enter()
  261.     {
  262.         cout<<"enter the value";
  263.         cin>>a;
  264.     }
  265.  
  266.     friend  void average(abc, xyz);
  267. };
  268.  
  269.  
  270. class abc
  271. {
  272.     int a;
  273. public:
  274.     void enter()
  275.     {
  276.         cout<<"enter the value";
  277.         cin>>a;
  278.     }
  279.  
  280.     friend  void average(abc, xyz);
  281. };
  282.  
  283.  
  284.  
  285. void average(abc ab, xyz xy)
  286. {
  287.     float c;
  288.     c=(ab.a+xy.a)/2.0;
  289.     cout<<"Average is"<<c;
  290.  
  291. }
  292.  
  293.  
  294.  
  295. int _tmain(int argc, _TCHAR* argv[])
  296. {
  297.     abc a;
  298.     xyz x;
  299.      a.enter();
  300.      x.enter();
  301.  
  302.      average(a,x);
  303.      system("pause");
  304.      
  305.     return 0;
  306. }
  307.  
  308. /*
  309. enter the value4
  310. enter the value5
  311. Average is4.5Press any key to continue . . .
  312. */
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. program to find greatest of 2 nos using friend functions
  336. program to find average of 2 nos using friend functions
  337. program to swap 2 nos using friend functions
  338.  
  339. // friend func.cpp : Defines the entry point for the console application.
  340. //
  341.  
  342. #include "stdafx.h"
  343. #include<iostream>
  344.  
  345. using namespace std;
  346.  
  347.  
  348. class abc;
  349.  
  350. class xyz
  351. {
  352.     int a;
  353. public:
  354.     void enter()
  355.     {
  356.         cout<<"enter the value";
  357.         cin>>a;
  358.     }
  359.  
  360.     friend  void greatest(abc, xyz);
  361. };
  362.  
  363.  
  364. class abc
  365. {
  366.     int a;
  367. public:
  368.     void enter()
  369.     {
  370.         cout<<"enter the value";
  371.         cin>>a;
  372.     }
  373.  
  374.     friend  void greatest(abc, xyz);
  375. };
  376.  
  377.  
  378.  
  379. void greatest(abc ab, xyz xy)
  380. {
  381.     if (ab.a>xy.a)
  382.         cout<<"greatest is "<< ab.a;
  383.     else if (ab.a<xy.a)
  384.         cout<<"greatest is "<< xy.a;
  385.     else
  386.         cout<<"both equal";
  387. }
  388.  
  389.  
  390.  
  391. int _tmain(int argc, _TCHAR* argv[])
  392. {
  393.     abc a;
  394.     xyz x;
  395.      a.enter();
  396.      x.enter();
  397.  
  398.      greatest(a,x);
  399.      system("pause");
  400.      
  401.     return 0;
  402. }
  403.  
  404.  
  405.  
  406. /*
  407. enter the value5
  408. enter the value10
  409. greatest is 10Press any key to continue . . .
  410. */
Advertisement
Add Comment
Please, Sign In to add comment