Car Owner Details Structure-Modern Programming Languages-Assignment Solution, Exercises of Programming Languages

I am student at Baddi University of Emerging Sciences and Technologies. To help my friends in other universities, I am uploading my solved assignments of different courses. Its for Modern Programming Languages course. Other can see if they are searching following: Structure, Assign, Attribute, Initialization, List, Direct, Value, Memory, Buffer, Integer

Typology: Exercises

2011/2012

Uploaded on 08/01/2012

parmitaaaaa
parmitaaaaa 🇮🇳

4.2

(111)

173 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Solution: Assignment No. 02
Semester: SPRING 2012
CS410 – VISUAL PROGRAMMING
Total Marks: 15
Assignment
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.
================================
docsity.com
pf2

Partial preview of the text

Download Car Owner Details Structure-Modern Programming Languages-Assignment Solution and more Exercises Programming Languages in PDF only on Docsity!

Solution: Assignment No. 02 Semester: SPRING 2012 CS410 – VISUAL PROGRAMMING

Total Marks: 15

Assignment

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.

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

docsity.com

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]; }

docsity.com