1. You are required to make a structure named “section”. The names of the two sections are secA and secB.
2. There are two members of this structure i.e. numberOfBoys and numberOfGirls.
3. In secA there are 48 boys and 6 girls while in secB there are 50 boys and 2 girls.
4. Write a function totalBoysAndGirls(). It takes two arguments by value. These arguments are the two section structures. Pass structures secA and secB to this function to calculate the total number of boys and total number of girls in the computer programming course and returns this sum in a structure of type section. Write the output of this function in a file “

include<fstream>
include<iostream>

struct section
{
int no_boys;
int no_girls;
int sum;
};
section total(section a,section b)
{
section c;
c.sum=c.no_boys+c.no_girls;
return c;
}
int main()
{

``````    section secA;
section secB;
secA.no_boys=48;
secA.no_girls=6;
secB.no_boys=50;
secB.no_girls=2;
section func=total(secA,secB);
return 0;
``````

}

data.txt”.
Write a function totalStudents() . It takes one argument by address. This argument is a pointer to the section structure. This function gives the sum of total number of students in the section or class. Pass the result of the previous step i.e. the structure in which you found the total number of boys and girls in the computer programming course. Use this function to find the total number of students in the computer programming course. Write the output of this function in the same file “data.txt”.
Please give your suggestions and need help.

Your function total() is incomplete. After declaring section c you need to populate its members with totals from a + b then you can calculate the sum as you have coded it. The sum can't be calculated until no_boys and no_girls are known.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.