El tipo de Dato 'string'; Ecuaciones / Escritura Ecuaciones/Casting de Tipo
Subtitles of the Movie
ÿþ [ 0 0 : 0 0 : 0 0 . 0 ] E s t e p r o g r a m a d e m o s t r a r á e c u a c i o n e s s i m p l e s e n l e n g u a j e C . [ 0 0 : 0 0 : 0 4 . 0 ] T o m a r é c a d a e c u a c i ó n , u n a o p e r a c i ó n d e a d i c i ó n , u n a d e s u s t r a c c i ó n , d i v i s i ó n y m u l t i p l i c a c i ó n y d e m o s t r a r é c a d a u n a d e e l l a s . [ 0 0 : 0 0 : 1 2 . 0 ] E l p r o g r a m a , c o m o e s t á a h o r a , a c e p t a r á d o s v a r i a b l e s , ' s u m A ' y ' s u m B ' , c o n v a l o r e s i n i c i a l e s . [ 0 0 : 0 0 : 2 0 . 0 ] L a e x p r e s i ó n d e a s i g n a c i ó n s i m p l e m e n t e s u m a r á ' s u m A ' m á s ' s u m B ' y a l m a c e n a r á l a r e s p u e s t a e n l a v a r i a b l e ' t o t a l ' . [ 0 0 : 0 0 : 2 9 . 0 ] N o t a r á q u e c a d a u n a d e e s t a s v a r i a b l e s h a s i d o d e c l a r a d a c o m o ' s h o r t ' . [ 0 0 : 0 0 : 3 2 . 0 ] A l c o m p i l a r e l p r o g r a m a n o a p a r e c e n n i e r r o r e s n i a d v e r t e n c i a s , y l u e g o a l e j e c u t a r l o m o s t r a r á e l t o t a l q u e e s p e r a b a m o s : 2 5 0 , [ 0 0 : 0 0 : 4 5 . 0 ] q u e e s s i m p l e m e n t e l a a d i c i ó n d e 1 0 0 m á s 1 5 0 . [ 0 0 : 0 0 : 5 0 . 0 ] S i c a m b i o e s t e c á l c u l o a u n a r e s t a c a m b i a n d o e l s i g n o m á s p o r e l s i g n o m e n o s , r e s t a r á ' s u m A ' m e n o s ' s u m B ' . [ 0 0 : 0 0 : 5 9 . 0 ] D e b o v o l v e r a c o m p i l a r e l p r o g r a m a y v o l v e r l o a e j e c u t a r y , [ 0 0 : 0 1 : 0 5 . 0 ] c o m o p u e d e v e r , l a r e s p u e s t a s e a l m a c e n a e n t o t a l c o m o u n m e n o s 5 0 . D e n u e v o , e s t á r e s t a n d o 1 0 0 m e n o s 1 5 0 . [ 0 0 : 0 1 : 1 2 . 0 ] A h o r a c a m b i o e s t o a u n s i g n o d e m u l t i p l i c a c i ó n , q u e e s e l a s t e r i s c o ( * ) . D e n u e v o , t e n g o q u e v o l v e r a c o m p i l a r y a e j e c u t a r e l p r o g r a m a y [ 0 0 : 0 1 : 2 5 . 0 ] c o m o p u e d e v e r , o b t e n g o 1 5 0 0 0 c o m o r e s p u e s t a , [ 0 0 : 0 1 : 3 0 . 0 ] q u e d e n u e v o e s 1 5 0 p o r 1 0 0 . [ 0 0 : 0 1 : 3 4 . 0 ] P o r ú l t i m o h a r é d e e s t a u n a e x p r e s i ó n d e d i v i s i ó n , q u e v a a d i v i d i r 1 0 0 e n 1 5 0 - d e s p u é s d e u n a c o m p i l a c i ó n l i m p i a l o e j e c u t a m o s . [ 0 0 : 0 1 : 5 0 . 0 ] N o t a r á q u e e n e s t e c a s o l a r e s p u e s t a e s c e r o . [ 0 0 : 0 1 : 5 3 . 0 ] E s o o c u r r e p o r q u e e s t a m o s d i v i d i e n d o a ' s u m A ' ( 1 0 0 ) e n ' s u m B ' ( 1 5 0 ) , q u e d a c o m o r e s u l t a d o a l g o c o m o 0 , 6 6 6 . [ 0 0 : 0 2 : 0 1 . 0 ] E s e n ú m e r o e s u n a f r a c c i ó n d e c i m a l y n o e s u n n ú m e r o e n t e r o , y l a v a r i a b l e t o t a l e s u n n ú m e r o e n t e r o d e t i p o ' s h o r t ' . [ 0 0 : 0 2 : 1 1 . 0 ] P o r l o t a n t o t o d o s l o s d e c i m a l e s e s t á n s i e n d o t r u n c a d o s y l a r e s p u e s t a s e n c i l l a m e n t e s e m u e s t r a c o m o c e r o . [ 0 0 : 0 2 : 1 7 . 0 ] P a r a r e s o l v e r e s t e p r o b l e m a p o d r í a m o s c a m b i a r e l t i p o d e d a t o d e ' t o t a l ' d e ' s h o r t ' a ' f l o a t ' . [ 0 0 : 0 2 : 2 5 . 0 ] V e a m o s e l e f e c t o q u e e s t o t i e n e . [ 0 0 : 0 2 : 2 8 . 0 ] D e s p u é s d e v o l v e r a c o m p i l a r l o , n o t e q u e o b t e n g o u n a a d v e r t e n c i a q u e d i c e " c o n v e r s i o n f r o m ' i n t ' t o ' f l o a t ' - p o s s i b l e l o s s o f d a t a " . [ 0 0 : 0 2 : 3 9 . 0 ] A l h a c e r d o b l e c l i c k e n e s e m e n s a j e , é l m e l l e v a a l a e x p r e s i ó n d e a s i g n a c i ó n , q u e e s t á r e a l i z a n d o l a o p e r a c i ó n ' s u m A ' d i v i d i d o ' s u m B ' . [ 0 0 : 0 2 : 4 7 . 0 ] E l p r o b l e m a a c á e s q u e t e n e m o s a d o s e n t e r o s d i v i d i é n d o s e e n t r e s í , y e l r e s u l t a d o s e e s t á a l m a c e n a n d o e n u n a v a r i a b l e d e t i p o ' f l o a t ' , c o m o l o e s ' t o t a l ' . [ 0 0 : 0 2 : 5 8 . 0 ] E l c o m p i l a d o r r e c o n o c e q u e c u a n d o u s t e d r e a l i z a e s t a o p e r a c i ó n e s m u y p o s i b l e q u e s e p i e r d a n d a t o s . [ 0 0 : 0 3 : 0 6 . 0 ] D e h e c h o , s i e j e c u t a m o s e l p r o g r a m a , n o t a r á q u e l a r e s p u e s t a s e g u i r á s i e n d o c e r o . [ 0 0 : 0 3 : 1 1 . 0 ] L a m a n e r a a d e c u a d a d e r e s o l v e r e s t o e s l a s i g u i e n t e : 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 m e z c l a d o s i . e . e n e s t e c a s o c o n e n t e r o s y f l o t a n t e s , [ 0 0 : 0 3 : 2 2 . 0 ] u s t e d d e b e h a c e r u s o d e l ' c a s t i n g ' d e t i p o s , p a r a h a c e r q u e c a d a i t e m d e d a t o s q u e a p a r e c e a l a d e r e c h a d e l s i g n o i g u a l s e a d e l m i s m o t i p o d e d a t o d e l q u e a p a r e c e e n e l l a d o i z q u i e r d o . [ 0 0 : 0 3 : 3 0 . 0 ] P a r a h a c e r l o p o d e m o s r e a l i z a r u n a c o n v e r s i ó n 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 t a m e n t e a n t e s d e ' s u m A ' y ' s u m B ' . [ 0 0 : 0 3 : 4 3 . 0 ] C u a n d o u s t e d l e h a c e c a s t i n g a u n a v a r i a b l e , C + + c r e a u n a c o p i a t e m p o r a l d e e l l a 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 3 . 0 ] E l c a s t i n g n o a l t e r a n i e l t i p o d e d a t o n i e l c o n t e n i d o d e l a v a r i a b l e o r i g i n a l , [ 0 0 : 0 3 : 5 8 . 0 ] s i m p l e m e n t e l o c a m b i a t e m p o r a l m e n t e . N o t e n e m o s q u e h a c e r l e ' c a s t i n g ' a ' t o t a l ' , p u e s é l y a e s d e t i p o ' f l o a t ' . [ 0 0 : 0 4 : 0 6 . 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 e l i m i n a l a a d v e r t e n c i a , y c o m o d e h e c h o l o h a c e , v a m o s a v o l v e r a e j e c u t a r e l p r o g r a m a . [ 0 0 : 0 4 : 1 4 . 0 ] P u e d e v e r a h o r a q u e a h o r a a p a r e c e 0 , 6 6 6 6 6 7 , q u e e s l a r e s p u e s t a a 1 0 0 d i v i d i d o 1 5 0 . [ 0 0 : 0 4 : 2 9 . 0 ] H a c e r c a s t i n g d e t i p o s p u e d e s e r u n p o c o c o n f u s o , y p o r e l l o l e d e d i c a r e m o s m á s t i e m p o m á s a d e l a n t e . [ 0 0 : 0 4 : 3 1 . 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
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 