Skip to main content

Ceng laboratory (4)

Page 1

LAB 8 In this long exercise, you model the chemical compounds made up of Hydrogen, Oxygen, Nitrogen and Carbon. You will need a struct atom. Consider the following: enum element {H,O,N,C}; struct atom { enum element what; \\ H,O,N or C struct atom* bond[4]; } Now, write the function void make_bond (struct atom * atom1, struct atom * atom2). This function takes two atoms as input and checks whether they are among the four elements above (by looking at what). If they are not, the function returns without doing anything. Then it checks whether they can still make bonds, in other words, their bonding capacity is not filled. Recall that Hydrogen makes 1 bond, Oxygen makes 2 bonds, Nitrogen makes 3 bonds and Carbon makes 4 bonds. If the bonding capacity of one of the atoms is filled, the function returns without doing anything. Finally, if the two atoms can still make bonds, the function connects them. That is, the function writes the address of the second atom in the array of bonds of the first atom and it writes the address of the first atom in the array of bonds of the second atom. (4 points for CENG, 7 points for EE) Use the function you wrote above to generate small molecules like carbon dioxide, water, etc. (2 points for CENG, 3 points for EE) Write the function void tell_molecule (struct atom * x). This function takes a pointer to an atom and iteratively looks at all the atoms that are, directly or indirectly, connected to it. In other words, it looks at the whole molecule. Then, the function prints out to the screen how many atoms of each type there are in this molecule. For example, if you send the address of any of the atoms in the carbon dioxide molecule you have just created to this function, the output should be like: 1 Carbon, 2 Oxygen (4 points for all)


LAB 8 Bu uzun çalışmada, Hidrojen, Oksijen, Azot ve Karbon unsurlarından müteşekkil kimyevi terkipleri modelleyeceksiniz. Size bir struct atom lazım olacak. Şunu kullanabilirsiniz: enum unsur {H,O,N,C}; struct atom { enum unsur nedir; \\ H,O,N or C struct atom* bag[4]; } Şimdi, void bagla (struct atom * atom1, struct atom * atom2) fonksiyonunu yazın. Bu fonksiyon girdi olarak iki atom alacak ve bunların yukarıdaki dört unsur arasında bulunup bulunmadığına bakacak (nedire bakarak). Bulunmazlarsa, fonksiyon hiçbir şey yapmadan geri dönecek. Daha sonra bu fonksiyon bu atomların hala bağ kurup kuramayacaklarına, yani bağ kurma kapasitelerinin dolmuş olup olmadığına bakacak. Hatırlayın, Hidrojen 1 bağ kurar, Oksijen 2 bağ kurar, Azot 3 bağ kurar ve Karbon 4 bağ kurar. Eğer atomlardan birinin bağ kurma kapasitesi dolmuşsa, fonksiyon hiçbir şey yapmadan geri dönecek. Nihayet, eğer atomlar hala bağ kurabilecek vaziyetteler ise, bu fonksiyon onları bağlayacak. Yani, ikinci atomun adresini ilk atomun bağ listesine yazacak, ilk atomun adresini ise ikincisinin bağ listesine yazacak. (4 points for CENG, 7 points for EE) Bu fonksiyonu kullanarak karbon dioksit, su, vs. gibi küçük molekülleri terkip edin (2 points for CENG, 3 points for EE) void molekul_anlat (struct atom * x) fonksiyonunu yazın. Bu fonksiyon bir atomu gösteren bir işaretçiyi girdi olarak alıp bu atoma, doğrudan veya aracılı, bağlı olan tüm atomlara bakacak. Bir başka deyişle, molekülün bütününe bakacak. Sonra, bu fonksiyon bu molekülde her türden kaç atom bulunduğunu ekrana yazacak. Mesela, yukarıda terkip ettiğiniz karbon dioksit molekülündeki herhangi bir atomun adresini bu fonksiyona gönderseniz, ekran çıktısı şuna benzer olmalı: 1 Karbon, 2 Oksijen (4 points for all)


Turn static files into dynamic content formats.

Create a flipbook