0% found this document useful (0 votes)
7 views2 pages

SH 2

The document outlines a Computer Programming course for the Mechatronics and Robotics Engineering program at Assiut University, including various programming tasks related to structure definitions in C++. It includes exercises on defining and initializing structures, handling errors in structure definitions, and creating programs to manipulate and display structured data. The document serves as a guide for students to practice their programming skills in relation to structures.

Uploaded by

kban3363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

SH 2

The document outlines a Computer Programming course for the Mechatronics and Robotics Engineering program at Assiut University, including various programming tasks related to structure definitions in C++. It includes exercises on defining and initializing structures, handling errors in structure definitions, and creating programs to manipulate and display structured data. The document serves as a guide for students to practice their programming skills in relation to structures.

Uploaded by

kban3363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Faculty of Engineering Mechatronics and Robotics Eng. Prog.

Assiut University Computer Programming (2)


2nd Level - Bylaw 2021 Code: EE 223 (Bylaw 2021)
Academic Year 2024/2025 Sheet 2
Assiut University 1st Semester Faculty of Engineering Structures Assiut University Faculty of Engineering

1) Consider the following type definition:


struct ShoeType
{
char style;
double price;
};

Given this structure type definition, what will be the output produced by the following code?
ShoeType shoe1, shoe2;
shoe1.style =’A’;
shoe1.price = 9.99;
cout << shoe1.style << " $" << shoe1.price << endl;
shoe2 = shoe1;
shoe2.price = shoe2.price/9;
cout << shoe2.style << " $" << shoe2.price << endl;

2) What is the error in the following structure definition?


struct Stuff
{
int b;
int c;
}

int main( )
{
Stuff x;
//other code
}

3) Given the following struct definition:


struct A
{
int memberB;
int memberC;
};

declare x to have this structure type. Initialize the members of x, memberB and memberC, to the
values 1 and 2, respectively.
(Note: This requests an initialization, not an assignment of the members.)
4) Write a definition for a structure type for records consisting of a person’s wage rate, accrued vacation
(which is some whole number of days), and status (which is either hourly or salaried). Represent
the status as one of the two char values ’H’ and ’S’. Call the type EmployeeRecord.

1
5) Here is an initialization of a structure type. Tell what happens with each initialization.
struct Date
{
int month;
int day;
int year;
};

a) Date dueDate = {12, 21, 22};


b) Date dueDate = {12, 21, 20, 22};
c) Date dueDate = {12, 21};

6) Write a structure definition for a type named StockRecord that has two member variables, one
named shoeInfo of the type ShoeType given in Problem (1) and one named arrivalDate of type
Date given in Problem (5). Then, declare a variable of type StockRecord and write a statement
that will set the year of the arrival date to 2006.
7) A phone number, such as (212) 767-8900, can be thought of as having three parts: the area code
(212), the exchange (767), and the number (8900). Write a program that uses a structure to store
these three parts of a phone number separately. Call the structure phone. Create two structure
variables of type phone. Initialize one, and allow the user to input the values for the other one.
Then display both numbers. Interaction with the program should look like this:
Enter your area code, exchange, and number: 415 555 1212
My number is (212) 767-8900
Your number is (415) 555-1212

8) A point on the two-dimensional plane can be represented by two numbers: an x coordinate and a
y coordinate. For example, (4,5) represents a point 4 units to the right of the vertical axis, and 5
units up from the horizontal axis. The sum of two points can be defined as a new point whose x
coordinate is the sum of the x coordinates of the two points, and whose y coordinate is the sum of
the y coordinates.
Write a program that uses a structure called point to model a point. Define three points, and allows
the user to input values to two of them. Then, set the third point equal to the sum of the other two,
and display the value of the new point. Interaction with the program might look like this:
Enter coordinates for p1: 3 4
Enter coordinates for p2: 5 7
Coordinates of p1+p2 are: 8, 11

9) Given the following structure definition of type Distance:


struct Distance
{
int feet;
float inches;
};

Create a structure called Volume that uses three variables of type Distance to model the volume
of a room. Initialize a variable of type Volume to specific dimensions, then calculate the volume
it represents, and print out the result. To calculate the volume, convert each dimension from a
Distance variable to a variable of type float representing feet and fractions of a foot, and then
multiply the resulting three numbers.
Dr. Abdelrahman Morsi

You might also like