corresponding memory location and how to get the value out or read the value

Corresponding memory location and how to get the

This preview shows page 3 - 4 out of 4 pages.

corresponding memory location and how to get the value out (or read the value from the memory location). This is done by using the dot operator (.) and assignment statements. Generally, a field is specified by using the name of the variable that refers to the structure, followed by a dot, followed by the name of the field. For example: If we declare a variable acc of type Account, then the three fields in acc are: Account acc; acc.accNumber; acc.accType; acc.balance; To assign values to each of these fields, we use statements such as the following: acc.accNumber = 123455; acc.accType ='S'; acc.balance = 15000; Similarly to output the data from a structure to the monitor, we use the dot operator: cout << "Account Number :" << acc.accNumber<< endl; cout << "Account Type : " << acc.accType<< endl; cout << "Account Balance : " << acc.balance << endl; Question 2 Using the Employee structure definition from Question 1, create an Employee structure, e1. e1 has an employee number of 345892, is a manager and has a salary of $15,000. Print all the data for e1 appropriately labeled. Solution: Employee e1; // create an Employee e1 //Assign values to the fields of e1 e1. empNum = 345892; e1. jobType = 'M'; e1. salary = 15000; //print the data in e1 cout << "******Data for e1*****" << endl; cout << "Employee Number : " << e1.empNum<< endl; cout << "Job Type : " << e1.jobType << endl; cout << "Employee Salary : $" << e1.salary<< endl; Employee empNum jobType salary M 345892 15000
Image of page 3
Structs 4 Question 3 Create another Employee structure, e2 . Prompt the user for e2
Image of page 4

You've reached the end of your free preview.

Want to read all 4 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes