Friday , 22 November 2024

CS410 Assignments # 2 Solution Spring 2012

Question # 01: [Marks: 02]

We initialize Owner structure, in Assignment No 1, as below;

owner1 = {“Ali Hussain”, “Muhammad Hussain”, “XYZ, Lahore”, “N/A”, 12, 12,2012, “4-Wheel”,

“Honda”, “BR-29536”, “LEV-0012”, 2011, 72000, Vehicle::Van};

Why we are unable to assign a direct value in last attribute of initialization list (enum Vehicle_Class)? (In Bold text). Provide reason in 2 – 3 lines at max.

Solution:

We are unable to assign a direct value to Vehicle::Van because the enum vehicle_Class is defined and declaired inside Vehicle class. So we use scope resolution operator to assign a value to a enum variable.

================================

Question # 02: [Marks: 03]

Write any alternate way to assign a value ‘Van’ in Vehicle_Class to initialize Owner structure. (Only code is required, no details or text required.)

Solution:

There is no easy way to initialize an enum variable. If you have, share it with me.

================================

Question # 03: [Marks: 02]

Why we use cin.sync () before cin.getline ()? Describe in 2 -3 lines at max.

Solution:


cin.sync() basically clear the memory buffer and any garbage values that could be left in the stream. If we did not use cin.sync() before cin.getline () garbage value is automatically assign to variable pass in cin.getline ().                                                          ================================

Question # 04: [Marks: 03]

If we write o2->v.vc = enum_choice; instead of o2->v.vc = (Vehicle::vehicle_class) enum_choice; why this would not work? (For reference, line no 127 of Assignment 1 solution).

Solution:

We can not write o2->v.vc = enum_choice because in this statement we are trying to assign an integer value to Vehicle::vehicle_class (enum) type variable. So data type mismatch error is generated by compiler.

================================

Question # 05: [Marks: 05]

Write an alternate code instead of using string copy function as written on line 83 of Assignment 1 solution. No marks are given to code which is not in working condition.

Solution:

char swapOwner[100];                      //Local variable

for(int i=0 ;i<100;i++)                     //Swapping is done

{

swapOwner[i]=o2->owner_name[i];

o2->owner_name[i] = o2->transferred_from[i];

o2->transferred_from[i] = swapOwner[i];

}

/****************** Download Solution From Here **********************\

 


Spring 2012_CS410_2_SOL

Check Also

CS410 Solved Subject Mega Collection form Final Term Papers

QNo.1   Synchronization objects? Answer:- A synchronization object is an object whose handle can be specified …

Leave a Reply

Your email address will not be published. Required fields are marked *

*