Fifth chapter structure data type (II.)

Source: Internet
Author: User
Question Fourth:
#include <iostream>
using namespace Std;

int main ()
{
Double htemp[7];
Double ltemp[7];
for (int i=0;i<7;++i) {
if (i==0)
cout<< "Today is Sunday, please enter today's temperature value:" <<endl;
Else
cout<< "Today is the Week" <<i<<, please enter today's temperature value: "<<endl;

cout<< "Maximum temperature:";
CIN >> Htemp[i];
cout<< "Minimum temperature:";
CIN >> Ltemp[i];
while (htemp[i]<ltemp[i]| | htemp[i]<0| | ltemp[i]<0) {
cout<< "You enter the temperature value is wrong, please lose" <<endl;
cout<< "Maximum temperature:";
CIN >> Htemp[i];
cout<< "Minimum temperature:";
CIN >> Ltemp[i];
}
}

Calculation temperature
Double avgh=0;
Double avgl=0;
for (int i=0;i<7;++i) {
Avgh+=htemp[i];
Avgl+=ltemp[i];
}
AVGH=AVGH/7;
AVGL=AVGL/7;
cout<< "This week the average maximum temperature is" <<avgH<< "degree. "<<endl;
cout<< "This week the average minimum temperature is" <<avgL<< "degree. "<<endl;
return 0;
}

Question Fifth:
#include <iostream>
using namespace Std;

int main ()
{
cout<< "Please input a int Value:" <<endl;
int ivalue;
cin>>ivalue;

if (ivalue<=0) {
cout<< "must be Positive" <<endl;
return 0;
}
Count
int temp=ivalue;
int icount=0;
while (temp) {
TEMP=TEMP/10;
icount++;
}
int *iarr=new Int[icount];

Temp=ivalue;
for (int i=0;i<icount;i++)
{
iarr[i]=temp%10;
temp/=10;
}

int i,j;
For (I=0,j=icount-1;i<j;++i,--J)
{
if (Iarr[i]!=iarr[j])
Break
}

if (I&GT;=J)
cout<< "This is palindrome number" <<endl;
Else
cout<< "This is not a palindrome number" <<endl;

delete []iarr;

return 0;
}

Question seventh:
#include <iostream>
#include <cmath>
using namespace Std;

struct root{
Double X1;
Double X2;
BOOL BRT;
};

Root Func2 (Double A, double b, double c) {
Judge whether there are real roots
if (b*b-4*a*c<0) {
cout<< "This equation has no real roots" <<endl;
Root RT;
rt.x1=rt.x2=0;
Rt.brt=false;
return RT;
}

root root;

Double sq=sqrt (B*B-4*A*C);
root.x1= (-B+SQ)/(2*A);
Root.x2= (-B-SQ)/(2*A);
Root.brt=true;

return root;
}

int main ()
{
Root Rt=func2 (1,-1,-6);
if (RT.BRT)
cout<< "x1=" <<rt.x1<< "/nx2=" <<rt.x2<<endl;

return 0;
}

Question eighth:
#include <iostream>
#include <cstring>
using namespace Std;

int main ()
{
cout<< "Please enter a string" <<endl;
Char str[50];
cin>>str;

int icap=0;
int ismall=0;
int num=0;
for (int i=0;str[i]!= '/0 '; ++i) {
if (str[i]>= ' A ' &&str[i]<= ' Z ')
++icap;
if (str[i]>= ' 0 ' &&str[i]<= ' 9 ')
++num;
if (str[i]>= ' a ' &&str[i]<= ' Z ')
++ismall;
}

cout<< "This string has a capital letter" <<iCap<< "a" <<endl;
cout<< "This string has lowercase letters" <<iSmall<< "a" <<endl;
cout<< "This string has number" <<num<< "a" <<endl;

return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.