第二章作业

本文通过多个C++编程实例,展示了基本数据类型的使用、运算符、条件表达式、类型转换等核心概念,并提供了三角形面积计算、一元二次方程求解等实际问题的解决方法。

例2.1

    /*******布尔类型使用举例*******/ 
#include "stdafx.h"

#include <iostream>  
#include <iomanip>  
using namespace std;  
       int main()  
    {  
        bool flag = true;  
        cout<<flag<<endl;  
        cout<<boolalpha<<flag<<endl;  
        cout<<flag+5<<endl;  
        flag = 0;  
        cout<<"执行语句flag=0;后flag的值为:"<<boolalpha<<flag<<endl;  
        flag = 0.0;  
        cout<<"执行语句flag=0.0;后flag的值为:"<<boolalpha<<flag<<endl;  
      
        return 0;  

}

例2.2

/*******功能:赋值表达式语句的使用*******/ 

#include "stdafx.h"

#include <iostream>  
using namespace std;  
  int main()  
{  
    int a, b, c, d;  
    a = 4;  
    b = a;  
    a = 5;  
    c = d = 6;  
    c*=a;  
    d%=a + b;  
    cout<<"a="<<a<<endl  
        <<"b="<<b<<endl  
        <<"c="<<c<<endl  
        <<"d="<<d<<endl;  
     return 0;  

}

例2.3

/*******数据自溢举例*******/
#include "stdafx.h"
#include <iostream>  
using namespace std;  
 
int main()  
{  
    short i, j, m, n;  
    i = 1000;  
    j = 1000;  
    m = i+j;  
    n = i*j;  
    cout<<"m= "<<m<<endl;  
    cout<<"n= "<<n<<endl;  
 
    return 0;  
}  

例2.4

/*******自增自减*******/  
#include "stdafx.h"
#include <iostream>  
using namespace std;  
 
int main()  
{  
    int i = 6, j, k, temp;  
    j = ++i;  
    k = i++;  
    ++i = 1;  
    cout<<"i= "<<i<<endl  
        <<"j= "<<j<<endl  
        <<"k= "<<k<<endl;  
 
    return 0;  
}  

例2.5
/*******条件运算符及条件表达式的应用*******/  
#include "stdafx.h"
#include <iostream>  
using namespace std;  
 
int main()  
{  
    char ch;  
    cout<<"please input a character: ";  
    cin>>ch;  
    ch = ch>='a'&&ch<='z'?ch-'a'+'A':ch;  
    cout<<"The result is: "<<ch<<endl;  
 
    return 0;  
}  

例2.6

/*******自动类型转换*******/  
#include "stdafx.h"
#include <iostream>  
using namespace std;  
 
int main()  
{  
    char ch = 'c';  
    int a, b = 13;  
    float x, y;  
    x = y = 2.0;  
    a = ch + 5;  
    x = b/2/x;  
    y = b/y/2;  
    cout<<"a= "<<a<<endl  
        <<"x= "<<x<<endl  
        <<"y= "<<y<<endl;  
 
    return 0;  

例题2.7

/*******强制转换类型*******/  
#include "stdafx.h"
#include <iostream>  
using namespace std;  
  int main()  
{  
    int ab, ac;  
    double b = 3.14;  
    char c = 'A';  
    ab = int(b);  
    ac = int(c);  
    cout<<"b= "<<b<<endl  
        <<"ab= "<<ab<<endl  
        <<"c= "<<c<<endl  
        <<"ac= "<<ac<<endl;  
 
    return 0;
}  

作业二

#include "stdafx.h"    
#include<iostream>  
#include<math.h>  
using namespace std;  
    int main()  
    {  
        float x,y,z,H,S,C;                    
        cout<<"请输入△的三个边长度"<<endl;  
        cin>>x;  
        cin>>y;  
        cin>>z;                                 
        if(x+y>z&&x+z>y&&y+z>x)              
        {  
            H=(x+y+z)/2;  
            S=sqrt(H*(H-x)*(H-y)*(H-z));    
            C=x+y+z;                          
            cout<<"△面积S="<<S<<endl;  
            cout<<"△周长C="<<C<<endl;  
        }  
        else                                   
        {  
            cout<<"您输入的数据不能组成相应的△"<<endl;  
               
        }  
        return 0;  
    } 
书本练习习题3(1)

#include "stdafx.h"    
#include <iostream>  
#include <math.h>  
    using namespace std;  
    int main()  
    {  
        int e=1,f=4,g=2;  
        float m=10.5,n=4.0,k;  
        k=(e+f)/g+sqrt((double)n)*1.2/g+m;  
            cout<<"k="<<k<<endl;  
      
        return 0;  
    } 

习题3(2)

#include "stdafx.h"      
#include <iostream>  
using namespace std;  
    int main()  
    {  
        float x=2.5,y=4.7,m;  
        int a=7;  
        m=x+a%3*(int(x+y)%2)/4;  
        cout<<"m="<<m<<endl;  
          
        return 0;  
    }  


#include "stdafx.h"      
#include<iostream>  
#include<math.h>  
using namespace std;  
 
int main()  
{  
    float a,b,c;   
    double x1,x2,e;   
    cout<<"请依次输入一元二次方程组ax^2+bx+c=0中系数a,b,c的值"<<endl;  
    cin>>a>>b>>c;                   //先求出e值方便判断是否有实根  
    e=b*b-4*a*c;  
        x1=(-b+sqrt(double(e)))/(2*a);  
        x2=(-b-sqrt(double(e)))/(2*a);  
 
    if(e>=0)  
    {  
        if(x1=x2)  
        {  
            cout<<"此方程只有一个解,x1=x2="<<x1<<endl;  
        }  
    else   
    {  
        cout<<"此方程有两个解,分别是:"<<x1<<endl;  
        cout<<"x1="<<x1<<endl;  
        cout<<"x2="<<x2<<endl;          
              
    }  
}  
    else  
    {  
        cout<<"该函数不存在实根"<<endl;  
    }  
 
return 0;  
}  


#include "stdafx.h"      
#include <iostream>  
using namespace std;  
      
    int main()  
    {  
    char a[25],b[25],c[25],e[25];          //定义四个一维字符型数量组    
        int k;      
        cout<<"欢迎进行名字加密与解密程序"<<endl;        //加密解密选择    
        cout<<"加密请输入“1”,解密请输入任意数字"<<endl;    
        cin>>k;     
            
        if(k==1)                                        //加密                          
        {    
            int i;    
            cout<<"请输入你要加密的名字"<<endl;         //输入要加密的名字    
            fflush(stdin);                              //清除输入缓存    
            cin>>a;                                     //从键盘获取字符                                     
            cout<<"该名字的加密成果为:"<<endl;         //加密结果输出    
            for(i=0;i<25;i++)    
            {    
                if(a[i]==0)    
                {    
                    break;    
                }    
                b[i]=a[i];    
                b[i]=b[i]+10;                           //加密方法    
                c[i]=b[i];    
                cout<<c[i];  
        
            }    
            cout<<endl;    
        }    
        else                                           //解密                                                
        {    
                
            cout<<"请输入你要解密的名字"<<endl;        //输入要解密的名字    
            fflush(stdin);                             //清除输入缓存    
            cin>>a;    
                
            cout<<"该名字的解密成果为:"<<endl;        //解密结果输出     
            for(int i=0;i<25;i++)    
            {    
                if(a[i]==0)    
                {    
                    break;    
                }    
                b[i]=a[i];    
                b[i]=b[i]-10;                          //解密方法    
                e[i]=b[i];    
                cout<<e[i];    
            }    
            cout<<endl;    
        }    
      
        return 0;  
    } 



最后表示。。各种不懂。。。大多都是参考照打。。。找不到的那些更不会。。。

发现要在vc上运行要打#include "stdafx.h"    。。但网上一般都是省略的。。

错误一般在于漏打各种标点。。。。


标题SpringBoot智能在线预约挂号系统研究AI更换标题第1章引言介绍智能在线预约挂号系统的研究背景、意义、国内外研究现状及论文创新点。1.1研究背景与意义阐述智能在线预约挂号系统对提升医疗服务效率的重要性。1.2国内外研究现状分析国内外智能在线预约挂号系统的研究与应用情况。1.3研究方法及创新点概述本文采用的技术路线、研究方法及主要创新点。第2章相关理论总结智能在线预约挂号系统相关理论,包括系统架构、开发技术等。2.1系统架构设计理论介绍系统架构设计的基本原则和常用方法。2.2SpringBoot开发框架理论阐述SpringBoot框架的特点、优势及其在系统开发中的应用。2.3数据库设计与管理理论介绍数据库设计原则、数据模型及数据库管理系统。2.4网络安全与数据保护理论讨论网络安全威胁、数据保护技术及其在系统中的应用。第3章SpringBoot智能在线预约挂号系统设计详细介绍系统的设计方案,包括功能模块划分、数据库设计等。3.1系统功能模块设计划分系统功能模块,如用户管理、挂号管理、医生排班等。3.2数据库设计与实现设计数据库表结构,确定字段类型、主键及外键关系。3.3用户界面设计设计用户友好的界面,提升用户体验。3.4系统安全设计阐述系统安全策略,包括用户认证、数据加密等。第4章系统实现与测试介绍系统的实现过程,包括编码、测试及优化等。4.1系统编码实现采用SpringBoot框架进行系统编码实现。4.2系统测试方法介绍系统测试的方法、步骤及测试用例设计。4.3系统性能测试与分析对系统进行性能测试,分析测试结果并提出优化建议。4.4系统优化与改进根据测试结果对系统进行优化和改进,提升系统性能。第5章研究结果呈现系统实现后的效果,包括功能实现、性能提升等。5.1系统功能实现效果展示系统各功能模块的实现效果,如挂号成功界面等。5.2系统性能提升效果对比优化前后的系统性能
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值