Answer on Question #47629 - Engineering, Other
1. Draw the flowchart and write a c program that reads in a number n and then outputs the sign off the square from 1 to n
Ex. If n=3, output should be 14 because 1²+2²+3²=1+4+9=14
Solution.
#include <iostream>
using namespace std;
int main()
{
int n=0;
cout<<"Enter the number: ";
cin>>n;
int k=0;
for(int i=1; i<=n; i++)
{
k+=powf(i,2);
}
cout<<"Result: "<<k;
//Stop console
cin.get();
cin.get();
return 0;
}</iostream>

2. In a class of n students print the total no of female students and the total no of male students and at the end print the total no of total no of students in n class both males and females
# Solutionc
include <iostream>
using namespace std;
const int N = 10;
class Student
{
bool male;
public:
void setMale(bool male)
{
this->male=male;
}
bool getMale()
{
return this->male;
}
};
class Class
{
public:
Student st[N];
};
```</iostream>
int main()
{
Class cs[15];
cs[N].st[1].setMale(false);
cs[N].st[5].setMale(false);
int male=0, female=0;
for(int i=0; i<N; i++)
{
if(cs[N].st[i].getMale())
{
male++;
}
else
{
female++;
}
}
cout<<"The total no of female students: "<<female<<endl;
cout<<"The total no of male students:"<<male<<endl;
cout<<"The both males and females:"<<male+female<<endl;
//Stop console
cin.get();
cin.get();
return 0;
}https://www.assignmentexpert.com/