题目内容 (请给出正确答案)
[主观题]

. #include 《filename.h》和 #include “filename.h” 有什么区别?

提问人:网友sky1102 发布时间:2022-01-06
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“. #include 《filename.h》和 #incl…”相关的问题
第1题
下面程序的功能是是读取文本文件in.txt中的全部内容,...

下面程序的功能是是读取文本文件in.txt中的全部内容,将文本存放到doc类的对象myDoc中。然后将myDoc中的字符字列反转,并输出到文件out.txt中。 文件int.txt的长度不大于1000字节。部分程序已给出,请将程序补充完成。 reverse()函数实现将myDoc中的字符序列反转,并将反转后的序列在屏幕上输出。 #include <iostream> #include <fstream> #include <cstring> using namespace std; class doc { private: char *str; //文本字符串首地址 int length; //文本字符个数 public: doc(char *filename); void reverse(); //将字符序列反转 ~doc(); void writeToFile(char *filename); }; doc::doc(char *filename) { ifstream myFile(filename); int len=1001,tmp; str=new char[len]; length=0; while((tmp=myFile.get())!=EOF) { str[length++]=tmp; } str[length]='\0'; myFile.close(); } void doc::reverse() { .............. } doc::~doc() { delete [] str; } void doc::writeToFile(char *filename) { ofstream outFile(filename); outFile< <str; outfile.close(); } int main() { doc mydoc("in.txt"); mydoc.reverse(); mydoc.writetofile("out.txt"); return 0;>

点击查看答案
第2题
请使用VC6或使用【答题】菜单打开考生目录proj3下的工程文件proj3,此工程中包含一个源程序文件proj
3.cpp,补充编制c++程序proj3.cpp,其功能是读取文本文件in.dat中的全部内容,将文本存放到doc类的对象myDoc中。然后将myDoc中的字符序列反转,并输出到文件out.dat中。文件in.dat的长度不大于1000字节。 要求: 补充编制的内容写在“//**********”与“//**********”两行之间。实现将myDoc中的字符序列反转,并将反转后的序列在屏幕上输出。不得修改程序的其他部分。 注意:程序最后已将结果输出到文件0ut.dat中,输出函数writeToFile已经给出并且调用。 //proj3.cpp include<iostream> include<fstream> include<catting> using namespace std;

class doc { private: char*sir;//文本字符串首地址 int length;//文本字符个数 public: //构造函数,读取文件内容,用于初始化新对象,filename是文件名字符串首地址 doc(char*filename); void reverse;//将字符序列反转 一doc; void writeToFile(char*filename); }; doc::doc(char}filename) { ifstream myFile(filename); int len=1001,tmp; atr=new char[1en]; length=0; while((trap=myFile.get)!=EOF) { str[1ength++]=trap; } str[1ength]=‘\0’; myFile.close; } void doc::reverse{ //将数组atr中的length个字符中的第一个字符与最后一个字符交换,第二个字符与倒数第二个 //字符交换…… //*************333*************

//*************666*************

} doc::~doe { delete[]str; } void doc::writeToFile(char*filename) { Ofstream outFile(filename); outFile<<str; outFile.close; } void main { doc myDoc(”in.dat”); myDoc.reveme; myDoc.writeToFile(”out.dat”); }

点击查看答案
第3题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明]

本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char*filename,char*word)是从指定的文件中得到单词。char*strdup(char*S)是复制S所指向的字符串,并返回复制字符串的地址。

[C程序]

include <stdio.h>

include <ctype.h>

include <string.h>

define MAXWORD 100

struct node {

char*word;

int count;

struct node*left;

struct node*right;

}

struct node*addtree(struct node*P,char*w)

{ int cond;

if(p==NULL){ /*向树中插入结点*/

P=(struct node*)malloc(sizeof(struct node));

P->word=strdup(w);

P->count=1;

(1) ;

}

elseif((oond=strcmp(w,p->word))==0) (2) ;

else if(cond<0)p->left=(3);

else p->right=(4);

return p;

}

main()

{ Struct node*root;

char word[MAXWORD];

root=NULL;

filename="example.dat";

while(getword(filename,word)!=EOF))

root=(5);

}

点击查看答案
第4题
请补充函数fun(),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各

请补充函数fun(),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。

注意:部分源程序给出如下。

请勿改动主函数main 和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。

试题程序:

include<stdio. h>

include<conio. h>

include<stdlib. h>

typedef struct ss

{

int data;

struct ss *next;

} NODE;

void fun(int n,char*filename)

{

NODE *h,*p, *s;

FILE *pf;

int i;

h=p= (NODE *) malloc (sizeof (NODE));

h->data=0;

for (i=1; i {

s=(NODE *)malloc (sizeof (NODE));

s->data=【 】;

【 】;

p=【 】

}

p->next=NULL;

if ((pf=fopen (filename, "w") ) ==NULL)

{

printf {"Can not open out9B.clat! ");

exit (0);

}

p=h;

fprintf (pf, "\n***THE LIST***\n");

print f ("\n***THE LIST***\n")

while (p)

{

fprintf (pf, "%3d", p->data)

printf ("%3d",p->data);

if (p->next ! =NULL)

{

fprintf (pf, "->");

printf ("->");

}

p=p->next;

}

fprintf (pf, "\n");

printf ("\n");

fclose (pf);

p=h;

while (p)

{

s=p;

p=p->next;

free (s);

}

}

main()

{

char * filename="out98. dat";

int n;

clrscr ();

printf (" \nInput n: ");

scanf ("%d", &n);

fun (n, filename);

}

点击查看答案
第5题
若输入I have a test.,则以下程序的运行结果为【 】。 include<stdio.h> main() { FILE*fp;

若输入I have a test.,则以下程序的运行结果为【 】。 include<stdio.h> main() { FILE*fp; char str[100],filename[10]; int i=0; if ((fp=fopen("test","w"))==NULL) { printf("can not open the file!\n"); exit(0); } getchar(); gets(str); while(str[i]!=) { if (str[i]>=a && str[i]<=z) str[i]=str[i]-32; fputc(str[i],fp); i++; } fclose(fp); fp=fopen("test","r"); fgets(str,strlen(str)+1,fp); printf("%s\n",str); fclose(fp); }

点击查看答案
第6题
t25:使用VC+ +2010打开考生文件夹下blank1中的解决方案。此解决方案的项目中包含-个源程序文件bla
nk1.c。在此程序中,通过定义学生结构体变量,存储了学生的学号、姓名和三门课的成绩。所有学生数据均以二进制方式输出到文件中。函数fun的功能是从形参filename所指的文件中读入学生数据,并按照学号从小到大排序后,再用二进制方式把排序后的学生数据输出到filename所指的文件中,覆盖原来的文件内容。请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:部分源程序在文件blank1.c中。 不得增行或删行,也不得更改程序的结构! include define N 5 typedef struct student { long sno; char name[10]; float score[3]; } STU; void fun(); } }

点击查看答案
第7题
以下程序中用户由键盘输入一个文件名,然后输入一串字符(用$结束输入)存放到此文件中,形成文本文

以下程序中用户由键盘输入一个文件名,然后输入一串字符(用$结束输入)存放到此文件中,形成文本文件,并将字符的个数写到文件尾部。请填空。 include <string.h> main() { FILE*fp: char ch,fname[32] int count=0: prinft("input the filename:"): scanf("%s",fname); if((fp=fopen(______,"w+"))==NULL) { printf("cant open file:%s\n",fname); exit(0): } printf("enter data:\n"): while((ch=getchar())!=$) {fputc(ch,fp): count++; } fprintf(______,"\n%d\n", count); fclose(fp): }

点击查看答案
第8题
使用VC++6.0打开源程序文件3.cpp。其中类TC用于把文件输出到屏幕,然后进行文件的分割。分割的方法
如下:第一个文件的大小是文件的前一半,另外一个文件的大小是剩余部分。此程序将in.txt文件中的内容输出到

屏幕,并且将文件按照以上方式分割,存于文件out1.txt和out2.txt中。

其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。

(1)从输入文件中获得一个字符,并判断是否到文件结

尾,如果到文件结尾,则退出循环。请在注释1后添加适当的语句。

(2)把获得的输入文件的内容存储到bur中,并且用len

记录下文件的长度。请在注释2后添加适当的语句。

(3)将输入文件的后一半内容存储在第二个文件中,请

在注释3后添加适当的语句。

(4)使用文件流对象打开输入文件in.txt,请在注释4

后添加适当的语句。

注意:增加代码或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。

试题程序:

include<iostream.h>

include<fstream.h>

include<stdlib.h)

classTC

{

public:

TC(char*fileName)

{

len=0;

fstreaminfile;

infile.open(fileName,ios::in);

charch;

//********1********

while

{

cout<<ch;

//********2********

}

infile.close;

}

voidsplit

{

fstreamoutfilel;

fstreamoutfile2;

outfile1.open("out1.txt",ios::out);

outfile2.open("out2.txt",ios::out);

inti=0:

for(i=0;i<len/2;i++)

{

outfilel<<buf[i];

}

do

{

//********3********

}

while(i!=len);

outfilel.close;

outfile2.close;

}

prwate:

intlen;

charbuf[1024];

};

voidmain

{

//********4********

TCobj;

obj.split;

return;

}

点击查看答案
第9题
假设指定文件中存储了若干自然数,如下程序功能是在屏幕上显示指定文件中的所有素数,其中文件名由
键盘输入;则划线处需要填写_______。 #include "stdio.h" int prime(int n){ if (n<2) return 0; for (________________) if (n%i="=0)" 1; } int main(){ file *fp; n, count="0;" char s1[20]; printf("please enter filename:\n"); scanf("%s",s1); ((fp="fopen(s1,"r"))!=_______){" while (________){ fscanf(fp,"%d",&n); (prime(n)) printf("%5d",n); fclose(fp);> A、int i=2;i<=n 2;i++ null !feof(fp)> B、int i=n/2;i>=2;i-- 0 !feof(fp)

C、int i=2;i<=n 0 2;i++ feof(fp)> D、i=n/2;i>=2;i-- NULL feof(fp)

点击查看答案
第10题
使用VC6打开考生文件夹下的工程test14_3,此工程包含一个test14_3.cpp,其中定义了类File,但类的定
义并不完整。请按要求完成下列操作,将程序补充完整。

(1)完成构造函数的定义,使数据成员filename,content指向为空。请在注释“//**1**”之后添加适当的语句;

(2)完成函数set_contents的定义,该函数为content申请新的空间来存储new_content的内容,成功返回true,失败返回false。请在注释“//**2**”之后添加适当的语句;

(3)完成成员函数copy(File & source,File & target)的定义,该函数实现将source的内容拷贝至target的功能,注意必须使用已经定义的成员函数来实现。请在注释“//**3**”之后添加适当的语句:

(4)完成析构函数的定义,要求释放content指向的空间。请在注释“//**4**”之后添加适当的语句。

输出结果如下:

file2:file1 contents

file2:file2 contents

注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

源程序文件testl4—3.cpp清单如下:

include<iostream.h>

include<string.h>

class File{

private:

char file_name[64];

char*contents;

public:

File(char*filename)

{

// ** 1 **

};

File::~File()

{

// ** 4 **

}

void printfile(){cout<<file_name<<":"<<contents<<endl;)

friend bool copy(File & source,File & target);

bool set_contents(char * new_contents);

};

bool File::set_contents(char*new_contents)

{

// ** 2 **

if(contents==NULL)

return false;

strcpy(contents,new_contents);

return true;

}

bool copy(File & source,File & target)

{

// ** 3 **

}

void main{)

{

File f1("filel"),f2("file2");

f1.set_contents("filel contents");

copy(f1,f2);

f2.printfile();

f2.set_contents("file2 contents,);

f2.printfile();

}

点击查看答案
第11题
阅读以下函数说明和C语言函数,将应填入(n)处的语句写在对应栏内。 【函数1.1说明】 本程序可以打印

阅读以下函数说明和C语言函数,将应填入(n)处的语句写在对应栏内。

【函数1.1说明】

本程序可以打印出如下图形(菱形):

*

***

*****

*******

*****

***

*

【函数2.1】

main()

{

int i,j,k;

for(i=0;i<=3;i++)

{

for(j=0;j<=2-i;j++)

printf(" ");

for((1))

printf("*");

printf("\n");

}

for(i=0;i<=2;i++)

{

for((2))

printf(" ");

for(k=0;k<=4-2*i;k++)

printf("*");

printf("\n");

}

}

【函数2.2说明】

通过本程序,可以从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“CsaiWgm”中保存,输入的字符串以“!”结束。

【函数2.2】

include "stdio.h"

main()

{

FILE *fp;

char str[100],filename[10];

int i=0;

if((fp=fopen("CsaiWgm","w"))==NULL)

{

printf("cannot open the file\n");

exit(0);

}

printf("please input a string:\n");

gets(str);

while((3))

{

if(str[i]>='a'&&str[i]<='z')

str[i]=(4);

fputc(str[i],fp);

(5);

}

fclose(fp);

fp=fopen("CsaiWgm","r");

fgets(str,stden(str)+1,fp);

printf("%s\n",str);

fclose(fp);

}

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信