Professional Documents
Culture Documents
Umar Asghar-70076360
Assignment-01
Assignment-01
44. else
45. {
46. st[i] = '0';
47. }
48. }
49.
50. for(int i=st.length()-1;i>=0;i--)
51. {
52. if (st[i] == '1' && carry == 1)
53. {
54. s.push(0);
55. }
56. else if (st[i] == '0' && carry == 1)
57. {
58. s.push(1);
59. carry = 0;
60. }
61. else
62. {
63. s.push(st[i]-'0');
64. }
65. }
66. while(!s.empty())
67. {
68. cout<<s.top();
69. s.pop();
70. }
71. }
72. }
73. //function to convert fraction part
74. void fraction(double fract)
75. {
76. fract=fract*2;
77. temp=fract;
78. cout<<temp;
79. fract=modf(fract,&integ);
80. if(i<9)
81. {
82. i++;
83. return fraction(fract);
84. }
85. }
86. };
87.
88. int main() {
Umar Asghar-70076360
Assignment-01
Assignment-01
89. ios_base::sync_with_stdio(false);
90. cin.tie(NULL);
91. double no,integ,fract;
92. cin>>no;
93. if(no>0)
94. {
95. fract=modf(no,&integ);
96. if(fract>0)
97. {
98. dtob o(no,true);
99. cout<<".";
100. o.fraction(fract);
101. }
102. else
103. {
104. dtob o(no,true);
105. }
106. }
107. else
108. {
109. cout<<"-";
110. no=no*-1;
111. fract=modf(no,&integ);
112. if(fract>0)
113. {
114. dtob o(no,true);
115. cout<<".";
116. o.fraction(fract);
117. }
118. else
119. {
120. dtob o(no,false);
121. }
122. }
123. }
124.
Output:
Umar Asghar-70076360
Assignment-01
Method: This difficult can be resolved not only with the help of the strtok() but
also it can be solved by using Stack Bottle Class in STL C++ by following the given
steps:
Umar Asghar-70076360
Assignment-01
Umar Asghar-70076360
Assignment-01
Umar Asghar-70076360