ºÃÎĵµ - רҵÎÄÊéд×÷·¶ÎÄ·þÎñ×ÊÁÏ·ÖÏíÍøÕ¾

C++¾­µä³ÌÐò´úÂë´óÈ«

ÓÉ ÌìÏ ·ÖÏí ʱ¼ä£º ¼ÓÈëÊÕ²Ø ÎÒҪͶ¸å µãÔÞ

//¸ù¾Ý°ë¾¶¼ÆËãÔ²µÄÖܳ¤ºÍÃæ»ý #include

const float PI=3.1416; //ÉùÃ÷³£Á¿(Ö»¶Á±äÁ¿)PIΪ3.1416 float fCir_L(float); //ÉùÃ÷×Ô¶¨Ò庯ÊýfCir_L()µÄÔ­ÐÍ float fCir_S(float); //ÉùÃ÷×Ô¶¨Ò庯ÊýfCir_S()µÄÔ­ÐÍ

//ÒÔÏÂÊÇmain()º¯Êý main() {

float r,l,s; //ÉùÃ÷3¸ö±äÁ¿

cout<<\ //ÏÔʾ×Ö·û´® cin>>r; //¼üÅÌÊäÈë

l=fCir_L(r); //¼ÆËãÔ²µÄÖܳ¤£¬¸³Öµ¸ø±äÁ¿l s=fCir_S(r); //¼ÆËãÔ²µÄÃæ»ý£¬¸³Öµ¸ø±äÁ¿s cout<<\ //ÏÔʾ¼ÆËã½á¹û cout<<\ }

//¶¨Òå¼ÆËãÔ²µÄÖܳ¤µÄº¯ÊýfCir_L() float fCir_L(float x) {

float z=-1.0; //ÉùÃ÷¾Ö²¿±äÁ¿

if (x>=0.0) //Èç¹û²ÎÊý´óÓÚ0£¬Ôò¼ÆËãÔ²µÄÖܳ¤ z=2*PI*x;

return(z); //·µ»Øº¯ÊýÖµ }

//¶¨Òå¼ÆËãÔ²µÄÃæ»ýµÄº¯ÊýfCir_S() float fCir_S(float x) {

float z=-1.0; //ÉùÃ÷¾Ö²¿±äÁ¿

if (x>=0.0) //Èç¹û²ÎÊý´óÓÚ0£¬Ôò¼ÆËãÔ²µÄÃæ»ý z=PI*x*x;

return(z); //·µ»Øº¯ÊýÖµ }

/* Program: P1-2.CPP Written by: Hap

Date written: 02:11:10 */

#include void main(void) {

double s1,s2,s3;

s1=1.5; /* ¶Ô±äÁ¿s1¸³Öµ*/ cout<<\

/* ¶Ô±äÁ¿s2¸³Öµ*/ s2=2.5; cout<<\

s3= /* ¶Ô±äÁ¿s3¸³Öµ*/ 3.5; cout<<\

cout<<\ //¼ÆËã²¢ÏÔʾ //¼ÆËã²¢ÏÔʾ cout<<\ }

#include main() {

double r=1.0;

1

cout<<\ double l;

l=2*3.1416*r; //¼ÆËãÔ²µÄÖܳ¤£¬¸³Öµ¸ø±äÁ¿l cout<<\ //ÏÔʾԲµÄÖܳ¤

double s=3.1416*r*r; //¼ÆËãÔ²µÄÃæ»ý£¬¸³Öµ¸ø±äÁ¿s cout<<\ //ÏÔʾԲµÄÃæ»ý

cout<<\ //ÏÔʾÌáʾÊäÈëµÄÐÅÏ¢ cin>>r; //¼üÅÌÊäÈë

l=2*3.1416*r; //¼ÆËãÔ²µÄÖܳ¤£¬¸³Öµ¸ø±äÁ¿l cout<<\ //ÏÔʾԲµÄÖܳ¤ s=3.1416*r*r;

cout<<\ //ÏÔʾԲµÄÃæ»ý }

#include //°üº¬iostream.hÍ·Îļþ void main() {

//Êä³ö×Ö·û³£Á¿¡¢±äÁ¿ºÍ×Ö·û´® char c1='A'; cout<<'W';

cout<

cout<<\ cout<<\

//Êä³öÕûÐͳ£Á¿¡¢±äÁ¿ºÍ±í´ïʽ int n=100; cout<<10; cout<

cout<<2*n<

//Êä³ö¸¡µãÐͳ£Á¿¡¢±äÁ¿ºÍ±í´ïʽ double pi=3.1415926,r=10.0,s=pi*r*r; cout<

cout<<2*r*pi<

//Ò»¸öcout¿ÉÒÔÊä³ö¶àÏîÊý¾Ý cout<<'W'<<\ cout<<\

cout<<\}

#include //°üº¬iostream.hÍ·Îļþ main() {

//ÊäÈëÊä³ö×Ö·û char c; cin>>c;

cout<<\

//ÊäÈëÊä³öÕûÐÍÊý¾Ý int n; cin>>n;

cout<<\

//ÊäÈëÊä³ö¸¡µãÐÍÊý¾Ý double x; cin>>x;

2

cout<<\

//ÊäÈëÌáʾ cout<<\ cin>>n;

cout<<\

//¶àÏîÊäÈë

cout<<\ cin>>c>>n>>x;

cout<<\}

#include //°üº¬iostream.hÍ·Îļþ main() {

//ÉùÃ÷ÕûÐͱäÁ¿ int a,b;

//´Ó¼üÅÌÉÏΪÕûÐͱäÁ¿¸³Öµ cout<<\ cin>>a; cout<<\ cin>>b;

//ÕûÐÍÊýµÄËãÊõÔËËã

cout<

//²âÊÔÒç³ö

short n=32767,m; //nÈ¡shortÀàÐ͵Ä×î´óÖµ cout<<\ m=n+1; //ÒýÆðÒç³ö cout<<\}

#include //°üº¬iostream.hÍ·Îļþ main() {

//ÉùÃ÷±äÁ¿£¬²¢³õʼ»¯ int a=010,b=10,c=0X10;

//ÒÔÊ®½øÖÆÐÎʽÏÔʾÊý¾Ý cout<<\ cout<<\ cout<<\

cout<<\

//Ò԰˽øÖÆÐÎʽÏÔʾÊý¾Ý cout<<\

cout<

cout<<\

//ÒÔÊ®Áù½øÖÆÐÎʽÏÔʾÊý¾Ý cout<<\

cout<

3

cout<<\ cout<<\

cout<<\

//°Ë¡¢Ê®ºÍÊ®Áù½øÖÆÊý»ìºÏÔËËã²¢Êä³ö cout<<\

cout<

//²âÊÔ°Ë¡¢Ê®ºÍÊ®Áù½øÖÆÊäÈë cout<<\ cout<<\ cout<<\

cout<<\ //Ö¸¶¨Ê®½øÖÆÊä³ö cout<<\ cout<<\ cout<<\}

#include //°üº¬iostream.hÍ·Îļþ

#include // iomanip.hÍ·Îļþ°üº¬setprecision()µÄ¶¨Òå main() {

//floatÐͱäÁ¿µÄÉùÃ÷¡¢ÊäÈë¡¢¼ÆËãºÍÊä³ö float fx,fy; cout<<\ cin>>fx; cout<<\ cin>>fy;

cout<

cout<

//cout<

//doubleÐͱäÁ¿µÄÉùÃ÷¡¢ÊäÈë¡¢¼ÆËãºÍÊä³ö float dx,dy; cout<<\ cin>>dx; cout<<\ cin>>dy;

cout<

cout<

//²âÊÔfloatºÍdoubleÀàÐÍÊý¾ÝµÄÓÐЧλ fx=10.0;fy=6.0; float fz=fx/fy; dx=10.0;dy=6.0; double dz=dx/dy; cout<<\

cout<

cout<

//floatÐÍÒç³ö float x=3.5e14;

cout<<\ cout<<\

4

cout<<\}

#include //°üº¬iostream.hÍ·Îļþ main() {

//×Ö·ûÀàÐͱäÁ¿µÄÉùÃ÷ char c1='A'; char c2;

//×Ö·ûÊý¾ÝµÄÔËËã¼°Êä³ö c2=c1+32;

cout<<\ cout<<\

//Êä³ö×Ö·û¼°ASCIIÂë

cout<

//ÊäÈë×Ö·û

cout<<\ cin>>c1>>c2;

cout<<\ c2=\}

#include //°üº¬iostream.hÍ·Îļþ main() {

char c1='\\a',TAB='\\t';

//ÕóÁåÒ»Éù

cout<

//ʹÓÃˮƽÖƱí·û

cout<<1<

//ʹÓÃË«ÒýºÅ

cout<<\

//ʹÓûسµ»»ÐÐ

cout<<\}

#include //°üº¬iostream.hÍ·Îļþ main() {

//ÉùÃ÷bool±äÁ¿£¬²¢³õʼ»¯ bool flag1=false,flag2=true;

//Êä³ö²¼¶û³£Á¿ºÍ±äÁ¿

cout<<\ cout<<\ cout<<\ cout<<\

//²¼¶û±äÁ¿µÄ¸³ÖµºÍÊä³ö int x=1;

flag1=x>0; //´æ·Å¹ØϵÔËËã½á¹û cout<<\

flag2=flag1; //boolÀàÐͱäÁ¿Ï໥¸³Öµ cout<<\

5

C++¾­µä³ÌÐò´úÂë´óÈ«

//¸ù¾Ý°ë¾¶¼ÆËãÔ²µÄÖܳ¤ºÍÃæ»ý#includeconstfloatPI=3.1416;//ÉùÃ÷³£Á¿(Ö»¶Á±äÁ¿)PIΪ3.1416floatfCir_L(float);//ÉùÃ÷×Ô¶¨Ò庯ÊýfCir_L()µÄÔ­ÐÍfloatfCir_S(float);//ÉùÃ÷×Ô¶¨Ò庯ÊýfCir_S(
ÍƼö¶È£º
µã»÷ÏÂÔØÎĵµÎĵµÎªdoc¸ñʽ
2p2855qhva667gi1z1ms
ÁìÈ¡¸£Àû

΢ÐÅɨÂëÁìÈ¡¸£Àû

΢ÐÅɨÂë·ÖÏí