El tipo de Dato 'string'; Ecuaciones / Demostración de depuración
Subtitles of the Movie
ÿþ [ 0 0 : 0 0 : 0 0 . 0 ] I n c l u i d o e n s u C D h a y u n p r o g r a m a d e d e m o s t r a c i ó n c o n n o m b r e d e m o 6 - e s u n p r o g r a m a d e p r á c t i c a d e d e p u r a c i ó n . [ 0 0 : 0 0 : 0 7 . 0 ] C o m o p u e d e v e r c u a n d o l o e j e c u t a m o s , e l p r o g r a m a c o m p i l a n o r m a l m e n t e p e r o n o p r o d u c e l o s r e s u l t a d o s c o r r e c t o s . [ 0 0 : 0 0 : 1 4 . 0 ] A n t e s q u e n a d a , p e r m i t a m e a m b i e n t a r l o u n p o c o a c e r c a d e l c ó d i g o . [ 0 0 : 0 0 : 1 7 . 0 ] L a s v a r i a b l e s q u e s e h a n d e c l a r a d o e i n i c i a l i z a d o [ 0 0 : 0 0 : 2 3 . 0 ] s o n e n s u m a y o r í a e n t e r o s d e t i p o ' s h o r t ' . C o m o p u e d e v e r , t o d o s l o s o n e x c e p t o l a v a r i a b l e ' a v e r a g e W o r k e r H o u r s ' , q u e e s d e t i p o ' f l o a t ' . [ 0 0 : 0 0 : 3 1 . 0 ] S e l e h a d a d o u n v a l o r i n i c i a l a c a d a u n o d e l o s e n t e r o s , c o m o e n e l c a s o d e l a s v a r i a b l e s ' w o r k e r ' y ' h o u r s ' . [ 0 0 : 0 0 : 3 9 . 0 ] L a s v a r i a b l e s ' t o t a l W o r k e r s ' y ' a v e r a g e W o r k e r H o u r s ' h a n s i d o i n i c i a l i z a d a s a c e r o . [ 0 0 : 0 0 : 4 4 . 0 ] E l s i g u i e n t e s e g m e n t o d e l p r o g r a m a e s h a c e r u n c á l c u l o s u m a n d o l a s d o s f i g u r a s d e t r a b a j a d o r e s ( ' w o r k e r ' ) p a r a o b t e n e r u n t o t a l d e t r a b a j a d o r e s ( ' t o t a l W o r k e r s ' ) [ 0 0 : 0 0 : 5 7 . 0 ] y s u m a r l a s h o r a s , ' h o u r s 1 ' m á s ' h o u r s 2 ' , p a r a o b t e n e r l a s h o r a s t o t a l e s , ' t o t a l H o u r s ' . [ 0 0 : 0 1 : 0 1 . 0 ] E l t e r c e r c á l c u l o q u e s e r e a l i z a e s c a l c u l a r e l p r o m e d i o , ' a v e r a g e W o r k e r H o u r s ' , q u e c o r r e s p o n d e a l t o t a l d e h o r a s , ' t o t a l H o u r s ' , d i v i d i d o e n e l n ú m e r o t o t a l d e t r a b a j a d o r e s , ' t o t a l W o r k e r s ' . [ 0 0 : 0 1 : 0 8 . 0 ] P o r ú l t i m o s e h a c e u s o d e u n a e x p r e s i ó n ' c o u t ' p a r a m o s t r a r l o s r e s u l t a d o s d e n u e s t r o c á l c u l o . [ 0 0 : 0 1 : 1 2 . 0 ] A n t e s d e c o m p i l a r y e j e c u t a r e l p r o g r a m a , u s t e d d e b e t e n e r c l a r o q u e l a r e s p u e s t a c o r r e c t a d e b e s e r 8 , 3 3 e n l a v a r i a b l e ' a v e r a g e W o r k e r H o u r s ' . [ 0 0 : 0 1 : 2 6 . 0 ] A l c o m p i l a r e l p r o g r a m a [ 0 0 : 0 1 : 2 8 . 0 ] v e m o s q u e n o p r o d u c e e r r o r e s n i a d v e r t e n c i a s , p e r o q u e l u e g o p r o d u c e u n r e s u l t a d o i n c o r r e c t o . [ 0 0 : 0 1 : 3 6 . 0 ] C o m o p u e d e v e r , e l p r o m e d i o d e h o r a s t r a b a j a d a s f u e 8 , p e r o a l v e r i f i c a r t o d o e l p r o c e s o a m a n o , s é q u e l a r e s p u e s t a d e b e s e r 8 . 8 3 . [ 0 0 : 0 1 : 4 4 . 0 ] R e g r e s a n d o a l p r o g r a m a - p u e d e v e r e n d o n d e e s t á e l p r o b l e m a ? P u e d e s e r p r u d e n t e q u e u s t e d s e t o m e u n p a r d e m i n u t o s p a r a r e v i s a r e s t e p r o g r a m a d e p r á c t i c a [ 0 0 : 0 1 : 5 3 . 0 ] y v e r s i p u e d e d e t e r m i n a r c u á l e s e l p r o b l e m a e n e l c ó d i g o . [ 0 0 : 0 1 : 5 6 . 0 ] A h o r a , d e s p u é s d e q u e t u v o l a o p o r t u n i d a d d e e x a m i n a r e l c ó d i g o , p u d o e n c o n t r a r e l p r o b l e m a ? [ 0 0 : 0 2 : 0 6 . 0 ] B u e n o , e l p r o b l e m a e s t á e n e l c á l c u l o d e l p r o m e d i o . [ 0 0 : 0 2 : 0 9 . 0 ] S e t i e n e u n a v a r i a b l e c o n n o m b r e ' a v e r a g e W o r k e r H o u r s ' q u e e s d e t i p o ' f l o a t ' , [ 0 0 : 0 2 : 1 4 . 0 ] q u e s e c a l c u l a c o m o l a d i v i s i ó n d e d o s v a r i a b l e s e n t e r o s d e t i p o ' s h o r t ' - ' t o t a l H o u r s ' y ' t o t a l W o r k e r s ' . [ 0 0 : 0 2 : 2 2 . 0 ] Y c o m o p u e d e v e r , l o s r e s u l t a d o s s o n i n c o r r e c t o s . [ 0 0 : 0 2 : 2 7 . 0 ] P a r a c o r r e g i r e s t o , h a g a ' c a s t i n g ' d e t i p o c o l o c a n d o l a p a l a b r a ' f l o a t ' e n t r e p a r é n t e s i s i n m e d i a n t e m e n t e a n t e s d e l a v a r i a b l e a l a q u e l e q u e r e m o s c a m b i a r t e m p o r a l m e n t e e l t i p o . [ 0 0 : 0 2 : 3 6 . 0 ] R e p i t o , h a c e r ' c a s t i n g ' n o c a m b i a e l t i p o d e d a t o , s o l o l o h a c e t e m p o r a l m e n t e . [ 0 0 : 0 2 : 4 3 . 0 ] A h o r a t e n e m o s u n c á l c u l o q u e i n v o l u c r a u n f l o t a n t e i g u a l a u n f l o t a n t e d i v i d i d o e n o t r o f l o t a n t e . [ 0 0 : 0 2 : 5 3 . 0 ] V o l v a m o s a c o m p i l a r e l p r o g r a m a p a r a v e r s i n o s d a l o s r e s u l t a d o s c o r r e c t o s . [ 0 0 : 0 3 : 0 0 . 0 ] Y c o m o p u e d e v e r , n u e s t r a r e s p u e s t a e s 8 , 8 3 3 3 . [ 0 0 : 0 3 : 0 5 . 0 ] E s i m p o r t a n t e q u e s i e m p r e v e r i f i q u e l o s r e s u l t a d o s c o n a l g u n o s d a t o s d e p r u e b a p a r a a s e g u r a r s e q u e s u s c á l c u l o s e n r e a l i d a d e s t á n f u n c i o n a n d o . [ 0 0 : 0 3 : 1 6 . 0 ] C o m o l o h a d e m o s t r a d o e s t e e j e m p l o , u n p r o g r a m a p o d r í a c o m p i l a r s i n e r r o r e s y s i n e m b a r g o p r o d u c i r r e s u l t a d o s i n c o r r e c t o s . [ 0 0 : 0 3 : 2 4 . 0 ] D e p e n d e d e u s t e d c o m o p r o g r a m a d o r v e r i f i c a r q u e s u c ó d i g o f u n c i o n a . [ 0 0 : 0 3 : 2 9 . 0 ] R e c u e r d e , e n v e z d e d e j a r q u e e l c o m p i l a d o r d e C r e a l i c e c o n v e r s i ó n d e t i p o s i m p l í c i t a , q u e p u e d e l l e v a r a r e s u l t a d o s i n e s p e r a d o s , [ 0 0 : 0 3 : 4 0 . 0 ] e s m e j o r h a c e r c a s t i n g d e t i p o s , q u e e s a l o q u e n o s r e f e r i m o s c o m o c o n v e r s i ó n d e t i p o s e x p l í c i t a . [ 0 0 : 0 3 : 4 7 . 0 ] U s t e d l e h a c e c a s t i n g d e t i p o s a u n í t e m d e d a t o s p r e c e d i é n d o l o c o n e l n o m b r e d e l t i p o d e d a t o s d e s e a d o . [ 0 0 : 0 3 : 5 2 . 0 ] C u a n d o u s t e d h a c e e s t o , C c r e a u n a c o p i a t e m p o r a l d e e s a v a r i a b l e u s a n d o e l n u e v o t i p o d e d a t o , [ 0 0 : 0 3 : 5 9 . 0 ] y e l h a c e r l o n o c a m b i a n i l o s c o n t e n i d o s n i e l t i p o d e l a v a r i a b l e o r i g i n a l . [ 0 0 : 0 4 : 0 4 . 0 ] C u a n d o u n a e c u a c i ó n c o n t i e n e t i p o s d e d a t o s e n t r e m e z c l a d o s u s t e d d e b e h a c e r ' c a s t i n g ' p a r a h a c e r q u e c a d a u n o d e l o s í t e m s q u e a p a r e c e n a l a d e r e c h a d e l s i g n o i g u a l [ 0 0 : 0 4 : 1 2 . 0 ] s e a n d e l m i s m o t i p o q u e l a v a r i a b l e q u e a p a r e c e a l a i z q u i e r d a d e l é l . [ 0 0 : 0 4 : 1 6 . 0 ] E s t a e s u n a r e a l i d a d d e C q u e p u e d e l l e g a r a s e r e n g o r r o s a , y p o r e l l o u s t e d d e b e p r a c t i c a r y e s t a r p e n d i e n t e d e e l l a s i e m p r e q u e r e a l i c e c á l c u l o s . [ 0 0 : 0 4 : 2 6 . 0 ] [ 0 0 : 0 4 : 2 8 . 0 ]
Tutorial Information
| Course: | C++ (Español) |
| Author: | Arthur L. Lee |
| SKU: | 33572 |
| ISBN: | 1-932808-26-4 |
| Release Date: | 2004-11-03 |
| Duration: | 5 hrs / 44 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 