Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class district
  4. {
  5. public:
  6. char name[20];
  7. float area;
  8. int population;
  9. void inp_data()
  10. {
  11. cout<<" Data\n"<<"Name of district:";
  12. cin>>name;
  13. cout<<"Area";
  14. cin>>area;
  15. cout<<"population";
  16. cin>>population;
  17. }
  18.  
  19. };
  20. district data[65],temp;
  21. static int keep=0;
  22. void print_data()
  23. {
  24.  
  25. int i=0;
  26. int account_no,p=0;
  27. while(data[i].area)
  28. {
  29. cout<<" District Data\n"<<"\nName:"<< data[i].name<<"\nArea"<<data[i].area<<"\npopulation"<<data[i].population<<endl<<endl;
  30. i++;
  31. }
  32. }
  33. void sort_area()
  34. {
  35. int i=0,p,q;
  36. while(data[i].area)
  37. i++;
  38. for (p=0; p < i-1; p++)
  39. {
  40. for (q=0; q< i-1-p; q++)
  41. {
  42. if (data[q].area > data[q+1].area)
  43. {
  44. temp=data[q];
  45. data[q]=data[q+1];
  46. data[q+1]=temp;
  47. }
  48. }
  49. }
  50. for( p=0 ; p<i; p++)
  51. {
  52. cout<<" District Data\n"<<"\nName:"<< data[i].name<<"\nArea"<<data[i].area<<"\npopulation"<<data[i].population<<endl<<endl;
  53.  
  54. }
  55. }
  56. void sort_population()
  57. {
  58. int i=0,p,q;
  59. while(data[i].population)
  60. i++;
  61. for (p=0; p < i-1; p++)
  62. {
  63. for (q=0; q< i-1-p; q++)
  64. {
  65. if (data[q].population > data[q+1].population)
  66. {
  67. temp=data[q];
  68. data[q]=data[q+1];
  69. data[q+1]=temp;
  70. }
  71. }
  72. }
  73. for( p=0 ; p<i; p++)
  74. {
  75. cout<<" District Data\n"<<"\nName:"<< data[i].name<<"\nArea"<<data[i].area<<"\npopulation"<<data[i].population<<endl<<endl;
  76.  
  77. }
  78. }
  79. int main()
  80. {
  81. int i,no,n,choice,e=1;
  82. while (e)
  83. {
  84. cout<<"1.Input Data of District"<<endl;
  85. cout<<"2.Print"<<endl;
  86. cout<<"3.Sort Using area"<<endl;
  87. cout<<"4.Sort Using population"<<endl;
  88. cout<<"5.End"<<endl;
  89. cout<<"Your choice ??"<<endl;
  90. cin>>choice;
  91. switch(choice)
  92. {
  93. case 1:
  94. data[keep].inp_data();
  95. keep++;
  96. break;
  97. case 2:
  98. print_data();
  99. break;
  100. case 3:
  101. sort_area();
  102. break;
  103. case 4:/*
  104. sort_population();
  105. break;
  106. */ case 5:
  107. e=0;
  108. break;
  109.  
  110. }
  111.  
  112. }
  113.  
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement