1 - Why do we need structs?
Structs allow us to group multiple data types together in a single unit.
2 - What are members in a struct?
The variables that are present in the struct are called members.
3 - How do you access a member inside a struct?
structName.member
4 - What is a nested struct?
A nested struct is a struct inside another struct. We could access data this way:
MajorStruct.MinorStruct.member
Quiz 1 solution:
#include <iostream>
using namespace std;
struct Advertising {
int numberOfAdsShown;
float percentageClicked;
float earningPerClick;
};
float findTotal(Advertising result){
float total = ((result.numberOfAdsShown * result.percentageClicked)*result.earningPerClick);
return total;
};
int main() {
Advertising today;
cout << "How many ads shown today?";
cin >> today.numberOfAdsShown;
cout << endl;
cout << "What percent were clicked?";
cin >> today.percentageClicked;
cout << endl;
cout << "How much did you earn per click?";
cin >> today.earningPerClick;
cout << endl;
cout << "The result was " << findTotal(today);
return 0;
}