Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MOBILE.H Alabama Mobiles Inc. designs and manufactures mobiles , lightweight “ki

ID: 3860418 • Letter: M

Question

MOBILE.H

Alabama Mobiles Inc. designs and manufactures mobiles, lightweight “kinetic sculptures” consisting of decorative objects and bars, each bar having a string tied to each end from which hang other bars or decorative objects.

A bar is a straight length of light plastic (negligable weight) with two other moblile elements hanging from it, one at each end of the bar. A bar will itself be hanging from a string, which may be tied anywhere along its length.

A decorative object is much heavier than any bar, but of negligable size and having no other elements hanging from it.

A well-designed mobile must have the weights of all the decorative items balanced, so that each bar in the mobile will naturally tend to hang horizontally.

2 The Assignment

Your task is to complete a program that reads a description of a mobile and computes, for each bar, the total weight hanging from that bar and then prints a report indicating, for each bar, how far off-balance that bar is (i.e., the absolute value of the difference between the weights hanging from each end of the bar).

Files for this assignment may be found  here or, if you are logged in on one of the CS Dept Linux machines, in ~zeil/Assignments/cs333/trees_balance/.

2.1 Input

The program reads, from standard input, a description of a mobile in an s-expression format (s-expressions are a common technique for representing trees in text form). A mobile is described either as

An integer number giving the weight of one of the decorations, or

A bar described using the format

where ID is a single-word identifier for the bar, L is an s-expression describing the (sub)mobile hanging from the left end of the bar, and R is an s-expression describing the (sub)mobile hanging from the right end of the bar. For example,

describes a mobile with 2 bars and 3 decorative objects.

2.2 Output

Your program will print the mobile description from the input, followed by a list of the bars with their connection points. The bars are listed, one per line, in the order that they occurred in the input. Each line should give the bar’s id, a space, then the absolute value of the difference in the weight between the two sides of the bar.

For example, given the input

the correct output would be

Explanation / Answer

MOBILE.H

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote