Chapter 9 Homework.docx - 1 Define a struct fruitType to store the following data about a fruit Fruit name(string color(string fat(int sugar(int and

Chapter 9 Homework.docx - 1 Define a struct fruitType to...

This preview shows page 1 - 3 out of 6 pages.

1. Define a struct, fruitType, to store the following data about a fruit: Fruit name (string), color (string), fat (int), sugar (int), and carbohydrate (int). A. #include<iostream> #include<string> using namespace std; struct fruitType { string name; string color; int fat; int sugar; int carbohydrate; }; int main() { struct fruitType obj; cout<<"Enter fruit details"; cout<<endl<<"Enter Name : "; cin>>obj.name; cout<<"Enter Color : "; cin>>obj.color; cout<<"Fat : "; cin>>obj.fat; cout<<"Sugar : "; cin>>obj.sugar; cout<<"Carbohydrate : "; cin>>obj.carbohydrate; cout<<"\nDetails of Fruit"; cout<<"\nName : "<<obj.name; cout<<"\nColor : "<<obj.color; cout<<"\nFat : "<<obj.fat; cout<<"\nSugar : "<<obj.sugar; cout<<"\nCarbohydrate : "<<obj.carbohydrate; return 0; }
Image of page 1
2. Consider the following statements: struct nameType struct courseType struct studentType { { { string first; string name; nameType name; string last; int callNum; double gpa; }; int credits; courseType course; char grade; }; }; studentType student; studentType classList[100]; courseType course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. a. student.course.callNum = "CSC230"; A. wrong. (type of callNum is int. so, we can't assignm string to it) b. cin >> student.name; A. wrong. (type of student.name is nameType. so, we can't use cin or cout on it) c. classList[0] = name; A. wrong. (type of classList[0] is studentType and os name is nameType. since they are of two
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 6 pages?

  • Fall '19

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 ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors