zoukankan      html  css  js  c++  java
  • 复数的实现1.3

    小白来啦!今天要写一个简单的完整的项目!

    内容:输入整数, 输出复数

    第一个文件,名为f1_const.h 符号声明文件

    //第一个文件,文件命名为f1_const.h  是个符号声明文件(基本每次作业都需要)
    
    const int TRUE = 1//相当于#defiine TRUE 1
    
    const int FALSE = 0const int OK = 1;
    
    const int ERROR = 1;
    
    const INFEASIBLE = -1;
    
    const int OVERFLOW = -2;
    
    typedef int Status;//这一句是定义类型,将Status定义为int,后面就用Status代替int,好处时用Status可以开辟空间,不会存在没有空间的问题

    第二个文件,名为complex.h 函数声明文件

    #include "f1_const.h"//因为包含了f1_const.h文件中定义的Status
    
    typedef float * Complex ;//定义新类型,实型指针
    
    Status Input(Complex,float,float);//输入函数的声明
    
    void Output(Complex);//输出函数的声明
    
     

    第三个文件,名为complex.c 函数定义文件

    #include "f1_const.h"
    #include <iostream>//这一句以及下一句都是由于使用了cout而需要的语句
    using namespace std;
    
    Status Input(Complex &C,float a,float b)//输入函数
    {
    C = new float[2];//定义一个长度为2 的数组
    if(!C) return ERROR;
    C[0]=a;
    C[1]=b;
    return OK;
    }
    
    void Output(Complex C)//输出函数  
    {
    cout<<C[0]<<'+'<<C[1]<<'i'<<endl;
    }

    第四个文件,名为main1.c文件  主函数文件(测试文件)

    #include "Complex.h"//因为调用了函数
    #include <stdio.h>//因为有scanf
    
    int main()
    {
    Complex x;
    float a,b;
    
    scanf("%f %f",&a,&b);
    
    Input(x,a,b);//输入
    Output(x);//输出
    return 0;
    }

     loading......

  • 相关阅读:
    JavaScript 内置函数有什么?
    cursor(鼠标手型)属性
    用CSS制作箭头的方法
    CSS 的伪元素是什么?
    用CSS创建分页的实例
    CSS 按钮
    网页布局中高度塌陷的解决方法
    CSS 进度条
    DOM导航与DOM事件
    DOM 修改与DOM元素
  • 原文地址:https://www.cnblogs.com/lysun/p/12593818.html
Copyright © 2011-2022 走看看