小白求解c++程序

qq_31205301 2015-09-10 07:29:56
这个是题 请问我写的的对吗 还有没有其他做法

写一个程序仅使用指针加载一组15个整数的随机数组
数从3至57(二)加倍其内容,(三)打印所述数组的每行10个值使用该内容
指针运算。
Write a program that using only pointers (a) loads an array of 15 integers with random number from 3 to 57 (b) doubles its contents, (c) prints the contents of the array 10 values per line using pointer arithmetic.
#include<iostream>
#include<stdlib.h>
#include<ctime>

using namespace std;
int main()
{
srand(time(NULL));
int array[15];
int *point;
point=&array[0]

int count =0

for( int i=0;i<15;i++)

{
array [i] =3+rand()%55;
cout<<*(point+i)*2<<" ";
cout ++;
if(count%10==0)

cout<<endl;
}
return 0;
}
...全文
139 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-09-11
  • 打赏
  • 举报
回复
//Create a text file with 10 records of the form:
//Model, string (10 characters),
//Cost (double),
//plate (6 characters) and
//customer ID (integer).
//Use a structure to record the data into the file.
//Your program will create this file,
//close it and then reopen to print the first and the last fields of these 10 records.
#include <stdio.h>
struct form {
    char   Model     [11];
    double Cost          ;
    char   plate     [ 7];
    int    customerID    ;
} rs[10],fs[10]={
    {"Modle0",0.0,"plate0",0},
    {"Modle1",1.0,"plate1",1},
    {"Modle2",2.0,"plate2",2},
    {"Modle3",3.0,"plate3",3},
    {"Modle4",4.0,"plate4",4},
    {"Modle5",5.0,"plate5",5},
    {"Modle6",6.0,"plate6",6},
    {"Modle7",7.0,"plate7",7},
    {"Modle8",8.0,"plate8",8},
    {"Modle9",9.0,"plate9",9},
};
FILE *f;
int i;
int main() {
    f=fopen("forms.txt","w");
    for (i=0;i<10;i++) {
        fprintf(f,"%s\n" ,fs[i].Model     );
        fprintf(f,"%lg\n",fs[i].Cost      );
        fprintf(f,"%s\n" ,fs[i].plate     );
        fprintf(f,"%d\n" ,fs[i].customerID);
    }
    fclose(f);
    f=fopen("forms.txt","r");
    for (i=0;i<10;i++) {
        fscanf(f,"%10s", rs[i].Model     );
        fscanf(f,"%lf" ,&rs[i].Cost      );
        fscanf(f,"%6s" , rs[i].plate     );
        fscanf(f,"%d"  ,&rs[i].customerID);
    }
    fclose(f);
    i=0;
    printf("rs[%d].Model     :%s\n" ,i,rs[i].Model     );
    printf("rs[%d].Cost      :%lg\n",i,rs[i].Cost      );
    printf("rs[%d].plate     :%s\n" ,i,rs[i].plate     );
    printf("rs[%d].customerID:%d\n" ,i,rs[i].customerID);
    i=9;
    printf("rs[%d].Model     :%s\n" ,i,rs[i].Model     );
    printf("rs[%d].Cost      :%lg\n",i,rs[i].Cost      );
    printf("rs[%d].plate     :%s\n" ,i,rs[i].plate     );
    printf("rs[%d].customerID:%d\n" ,i,rs[i].customerID);
    return 0;
}
//rs[0].Model     :Modle0
//rs[0].Cost      :0
//rs[0].plate     :plate0
//rs[0].customerID:0
//rs[9].Model     :Modle9
//rs[9].Cost      :9
//rs[9].plate     :plate9
//rs[9].customerID:9
//
qq_31205301 2015-09-10
  • 打赏
  • 举报
回复
这个不会写阿
Create a text file with 10 records of the form: Model, string (10 characters), Cost (double), plate (6 characters) and customer ID (integer). Use a structure to record the data into the file. Your program will create this file, close it and then reopen to print the first and the last fields of these 10 records.
heroesjun 2015-09-10
  • 打赏
  • 举报
回复
count++吧。

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧