C++第三次实验



一、代码

/* 
 *文件名称: 了
 *作    者: 袁明杰 
 *完成日期: 2015     年  3   月   27 日 
 *版 本 号:v1.0 
 *对任务及求解方法的描述部分:正整数类
 *输入描述:略
 *问题描述:并通过一系列的成员函数对其性质进行做出判断或列出相关联的数值 
 *程序输出: 略 
 *问题分析: 模仿已经给出的main()函数,完成你所设计的各个成员函数的测试。
 *算法设计:下面给出类声明,请实现各成员函数。  
 */  
#include<iostream>  
using namespace std;  
class NaturalNumber  
{
private:  
    int n;   
public:  
    void setValue (int x)
	{
		n=x;
		if(x>0&&x==(int)x)
			cout<<x<<"是正整数"<<endl;
	}
    int getValue()
	{
		return n;
	}
    bool isPrime()
	{
		 int a;  
         for(a=2;a<=n;a++)
		 {
			 if(n%a==0)
				 break;
		 }
		 if(n==a)  
        return true;  
    else  
        return false;
	}
    void printFactor()
	{
		 int a;  
    for(a=1;a<=n;a++)  
    {  
        if(n%a==0)  
            cout<<a<<" ";  
    } 
	}

    bool isPerfect()
{
     int a,sum=0;  
        for(a=1;a<n;a++)  
    {  
        if(n%a==0)  
            sum=sum+a;  
    }  
    if(sum==n)  
        return true;  
    else  
        return false;  
}  

		 
    bool isReverse(int x);

    bool isDaffodil(int x)
{  
    if(x==1)  
        return true;  
    else if(x<10)  
        return false;  
    else if(x<100)  
    {int a,b;  
    a=x/10;b=x-a*10;  
    if((a*a*a+b*b*b)==x)  
        return true;  
    else  
        return false;  
    }  
    else if(x<1000)
	{
        int a,b,c;
		a=x/100;b=(x-a*100)/10;c=x-a*100-b*10;
        if(x==(a*a*a+b*b*b+c*c*c))  
            return true;  
        else  
            return false;  
    }  
  }
    void printDaffodils() 
{  
    int x;  
    for(x=2;x<n;x++)  
    {  
        if(x<100&&x>10)  
        {int a,b;  
        a=x/10;b=x-a*10;
		if((a*a*a+b*b*b)==x)  
            cout<<x<<" ";  
        }  
        else if(x<1000&&x>100)  
        {  
            int a,b,c;  
            a=x/100;b=(x-a*100)/10;c=x-a*100-b*10;  
            if(x==(a*a*a+b*b*b+c*c*c))  
                cout<<x<<" ";  
        }  
    }  
}
};		
void main()  
{  
    NaturalNumber nn;   
    nn.setValue (6);  
    cout<<nn.getValue()<<(nn.isPrime()?"是":"不是")<<"素数" <<endl;  
  
    nn.setValue (37);   
    cout<<nn.getValue()<<(nn.isPrime()?"是":"不是")<<"素数" <<endl;  
  
    nn.setValue (84);   
    cout<<nn.getValue()<<"的因子有:";  
    nn.printFactor();
    cout<<endl;  
    nn.setValue(888);  
    cout<<nn.getValue()<<"的水仙花数有:  ";  
    nn.printDaffodils();  
    cout<<endl;  
}  

二、运行结果

三、心得体会

1.在编写这个程序时,有两种方法,既可以在类里声明,类外定义,也可以直接在类里面定义。

2.在编写程序时一定要记住用英文半角。

3.在类里面定义的时候不能加分号。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
华南理工大软件学院2016级VC 实验报告:学生信息管理系统 附文档,这套系统的功能分为两部分,学生部分和教务管理员部分。包括系统功能模块划分;类体系设计,即主要数据和函数功能描述;界面设计等。   1)学生功能:查看信息:个人基本信息,课表,成绩表等内容    修改信息:可修改个人基本信息   2)教务员功能: 查看信息:学生个人基本信息、课表、成绩等内容   修改信息:学生个人基本信息、课表、成绩等内容   添加学生信息:学生个人基本信息后对同班级同年级的学生进行成绩表和课表的初始化   删除学生全部信息   展示同专业同年级学生的基本信息   对同专业同年级的学生的各科成绩进行排名   3)其他功能:分文件储存不同专业不同年级学生的信息资料,方便信息的处理   添加新年级和专业的数据并初始化   各模块说明:   1)基本信息类:个人基本信息,信息的生成和获取   2)学生信息类:继承于基本信息类,增加学生特有的信息,信息的生成和获取,<  3)课表类:一周的课表,课表的生成和获取,<  4)成绩表类:考试科目的成绩表,成绩表的生成和获取,<  5)图形类:通过定义函数来生成UI图形,避免了大量的代码重复,简化了程序,增加了程序的可读性   6)学生类:包含学生有关的信息的类,同时通过函数来实现学生的操作   7)管理员类:包含学生有关的信息的类,同时通过函数来实现管理员的操作   8)主函数: 仅需通过包含学生类和管理员类,使用其中的操作函数来实现操作
Requirements 1. Simulate a Unix file system on your Windows Platform 2. Understand the file system on Unix system, and the usage of i-nodes 3. Implement the function of sub-directory 4. The task needs to be completed using C++ or C 5. Tasks/Functionalities The following functions are required in your file system: 1. Allocate 16MB space in memory as the storage for your file system. The space is divided as blocks with block size 1KB Assume block address length is 32-bit; Design the information contained in i-node The i-node should support up to 10 direct block addresses The i-node should support at least one indirect block address 2. The fist block is used for storing the i-node for the root directory(/). While your program is lunched, two directories (/dir1 and / dir1/dir2) should be created, and also two files need to be written as /dir1/file1 and /dir1/dir2/file2 (5 marks) 3. File 1 and 2 contain the message of “This is file 1.” and “This is file2”. 4. Following commands should be supported in your system: a) Create a file:createFile fileName fileSize (10 marks) i.e.:createFile /dir1/myFile 1024 (in bytes) if fileSiz > max file size, print out an error message. The file content is filled up with filename + repeated digits from 0 - 9 i.e.: “myFile012345678901234567890123….” b) Delete a file:deleteFile filename (10 marks) i.e.:deleteFile /dir1/myFile c) Create a directory:createDir (5 marks) i.e.:createDir /dir1/sub1 d) Delete a directory:deleteDir (5 marks) i.e.: deleteDir /dir1/sub1 (The current working directory is not allowed to be deleted) e) Change current working direcotry:changeDir (5 marks) i.e.: changeDir /dir2 f) List all the files and sub-directories under current working directory:dir (5 marks) You also need to list at least two file attributes. (i.e. file size, time created, etc.) g) Copy a file : cp (5 marks) i.e.: file1 file2 h) Display the usage of storage space:sum (10 marks) Display the usage of the 16MB
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值