# Lecture 11: Electrochemistry Introduction

-

English
11 pages
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

• cours magistral
Lecture 11: Electrochemistry Introduction • Reading: Zumdahl 4.10, 4.11, 11.1 • Outline – General Nomenclature – Balancing Redox Reactions (1/2 cell method) – Electrochemical Cells
• oxidation gain
• sb sb
• -2 +5 +6 +2 oxidation reduction cus
• reduction
• oxidation
• redox reaction
• electrons

Sujets

##### Reaction

Informations

 Publié par Nombre de lectures 25 Langue English
Signaler un problème
MassachusettsInstituteofTechnologyDepartmentofElectricalEngineeringandComputerScience
6.087:PracticalProgramminginC
IAP2010
ProblemSet3SolutionsControlﬂow.Functions.Variablescope.Staticandglobalvariables.I/O:printfandscanf.FileI/O.Characterarrays.Errorhandling.Labelsandgoto.
Out:Wednesday,January13,2010.
Problem3.1
Due:Friday,January15,2010.
(b)Now,modifythefibonacci()functionbymakingthevariablesa,b,andcregistervariables.Recompileandrunthecode.Howlongdoesasingleiterationtakenow,onaverage?Turninaprintoutofyourmodiﬁedcode(thefibonacci()functionitselfwouldsuﬃce).Answer:Here’sthemodiﬁedfibonacci()functionforpart(b):voidf i b o n a c c i( ){/h e r ea r et h ev a r i a b l e st os e ta sr e g i s t e r s/r e g i s t e runsignedi n ta =0 ;r e g i s t e runsignedi n tb =1 ;r e g i s t e runsignedi n tc ;i n tn ;
/don o te d i tb e l o wt h i sl i n e/r e s u l t sb u f f e r[ 0 ]=a ;r e s u l t sb u f f e r[ 1 ]=b ;f o r( n= 2 ;n<NMAX;n++){c=a+ b ;
1
r e s u l t sb u f f e r[ n ]=c;/s t o r ec o d ei nr e s u l t sb u f f e r/a;= b b =c ;}}
Onmy64-bitmachine(resultsmaydiﬀerslightlyfor32-bitmachines),themodiﬁedfunctiontook0.000111mseconaverage.
(c)Modifythefibonacci()functiononemoretimebymakingthevariablenalsoaregistervariable.Recompileandrunthecodeoncemore.Howlongdoesasingleiterationtakewithallfourvariablesasregistervariables?Answer:Here’sthemodiﬁedfibonacci()functionforpart(c):voidf i b o n a c c i( ){/h e r ea r et h ev a r i a b l e st os e ta sr e g i s t e r s/r e g i s t e runsignedi n ta =0 ;r e g i s t e runsignedi n tb =1 ;r e g i s t e runsignedi n tc ;r e g i s t e ri n tn ;
/don o te d i tb e l o wt h i sl i n e/r e s u l t sb u f f e r[ 0 ]=a ;r e s u l t sb u f f e r[ 1 ]=b ;f o r( n= 2 ;n<NMAX;n++){c=a+ b ;r e s u l t sb u f f e r[ n ]=c;/s t o r ec o d ei nr e s u l t sb u f f e r/a= b ;b =c ;}}
Onmy64-bitmachine(resultsmaydiﬀerslightlyfor32-bitmachines),thefurthermodiﬁedfibonacci()functiontook3.4e-05mseconaverage.
Problem3.2
Wesplitthecodeintoseveralﬁles:main.c,dict.c,anddict.h.Thecontentsoftheseﬁlesaredescribedbrieﬂybelow.
2
main.c:#include<stdio.h>#include<stdlib.h>#include"dict.h"
intmain(){...}
dict.c:#include"dict.h"
/*datastructureforthedictionary*/char*thedictionary[1000];
char*lookup(char[]){...}
dict.h:/*datastructureforthedictionary*/char*thedictionary[1000];
Problem3.3
(a)i n tf a c t o r i a l(i n tn ){ i n ti ,r e t= 1 ;f o r( i;= 2 i<=n ;i ++)r e t=i ;returnr e t;}
3
Answer:i n tf a c t o r i a l(i n tn ){i n ti = 1 ,r e t;= 1 while(++ i<=n )r e t=i ;returnr e t;}
(b)#incl ude<s t d l i b. h>
doubler a n dd o u b l e( ){ /g e n e r a t erandomnumberi n[ 0, 1 )/doubler e t= (double) r a n d( ) ;returnr e t/ (RANDMAX+ 1 ) ;}
i n ts a m p l eg e o m e t r i cr v (doublep ){doubleq ;i n tn =0 ;do{q=r a n dd o u b l e( ) ;n++;}while( q>=p ) ;returnn ;}
Note:Youonlyneedtomodifythesamplegeometricrv()function.Answer:i n ts a m p l eg e o m e t r i cr v (doublep ){doubleq ;i n tn=0 ,c o n d i t i o n=1 ;while( c o n d i t i o n){q=r a n dd o u b l e( ) ;n++;c o n d i t i o n=q>=p ;} returnn ;}
4
Problem3.4
’wc’isaunixutilitythatdisplaythecountofcharacters,wordsandlinespresentinaﬁle.Ifnoﬁleisspeciﬁeditreadsfromthestandardinput.Ifmorethanoneﬁlenameisspeciﬁeditdisplaysthecountsforeachﬁlealongwiththeﬁlename.Inthisproblem,wewillbeimplementingwc.Oneofthewaystobuildacomplexprogramistodevelopititeratively,solvingoneproblematatimeandtestingitthroroughly.Forthisproblem,startwiththefollowingshellandtheniterativelyaddthemissingcomponents.#incl ude<s t d i o. h>#incl ude<s t d l i b. h>i n tmain(i n ta r g c,chara r g v[ ] ){FILEf p=NULL ;i n tn f i l e s=−−a r g c ;/i g n o r et h enameo ft h eprogrami t s e l f/i n ta r g i d x=1;/i g n o r et h enameo ft h eprogrami t s e l f/charc u rrfile =" ";charc ;/c o u n to fwords,l i n e s,c h a r a c t e r s/unsignedlongnw=0 ,n l=0 , nc=0;
i f(n f i l e s==0){f p=s t d i n;/s t a n d a r di n p u t/nfiles ++;} e l s e/s e tt of i r s t/{c u r r f i l e =a r g v[a r g i d x ++];f p=f o p e n ( c u r r f i l e," r ") ;} while(n f i l e s>0)/f i l e sl e f t>0/{i f(f p==NULL){f p r i n t f ( s t d e r r," U n a b l etoopeninput \ n ") ;e x i t(1 ) ;} nc=nw=n l=0;while( (c=g e t c(f p) ) !=EOF){/TODO:FILLHEREp r o c e s st h ef i l eu s i n gg e t c ( f p )/} p r i n t f(" % ld% s \ n ", nc , c u r r f i l e) ;/n e x tf i l ei fe x i s t s/n f i l e s−−;i f(n f i l e s>0){c u r r f i l e =a r g v[a r g i d x ++];f p=f o p e n ( c u r r f i l e," r ") ;}}return0 ;}
Hint:Inordertocountwords,countthetransitionsfromnon-whitespacetowhitespacecharacters.
5
Answer:Here’sthecodewiththeshellﬁlledin/6 . 0 8 7IAPS p r i n g2 0 1 0Problems e t2/#incl ude<s t d i o. h>#incl ude<s t d l i b. h>
i n tmain(i n ta r g c,chara r g v[ ] ){FILEf p=NULL ;i n tn f i l e s=−−;a r g c /i g n o r et h enameo ft h eprogrami n ta r g i d x=1;/i g n o r et h enameo ft h eprogramcharc u rrfile =" ";charc ;/f o l l o w i n gu s e dt oc o u n twords/enums t a t e{INSIDE, OUTSIDE};enums t a t ec u r r s t a t e=INSIDE ;
/c o u n to fwords,l i n e s,c h a r a c t e r s/unsignedlongnw=0 ,n l=0 , nc=0;
i f(n f i l e s==0){f p=s t d i n;/s t a n d a r di n p u t/nfiles ++;} e l s e/s e tt of i r s t/{c u r r f i l e =a r g v[a r g i d x ++];f p=f o p e n ( c u r r f i l e," r ") ;} while(n f i l e s>0)/f i l e sl e f t>0/{i f(f p==NULL){f p r i n t f ( s t d e r r," U n a b l etoopeninput \ n ") ;e x i t(1 ) ;} /TODO:FILLHEREp r o c e s st h ef i l eu s i n gg e t c ( f p )/nc=nw=n l=0;while( (c=g e t c(f p) ) !=EOF){nc++;i f(c==’\ n ’){nl ++;} i f(i s s p a c e( c ) ){i f(c u r r s t a t e==INSIDE )nw++;currstate=OUTSIDE ;} e l s e{
6
i t s e l f/i t s e l f/
}
}
currstate=INSIDE;}} /u p d a t et o t a l s/
p r i n t f(" % ld% ld% ld% s \ n ", n l, nw , nc ,c u r r f i l e) ;/n e x tf i l ei fe x i s t s/n f i l e s−−;i f(n f i l e s>0){c u r r f i l e =a r g v[a r g i d x ++];f p=f o p e n ( c u r r f i l e," r ") ;}
7
Problem3.5