请解释这段代码(C++),另:1200分找师傅

来源:百度知道 编辑:UC知道 时间:2024/09/23 23:36:43
// example about structures
#include ‹iostream.h›
#include ‹string.h›
#include ‹stdlib.h›

struct movies_t {
char title [50];
int year;
}mine, yours;

void printmovie (movies_t movie);

int main () {
char buffer [50];
strcpy (mine.title, "2001 A Space Odyssey");
mine.year = 1968;
cout << "Enter title: ";
cin.getline (yours.title,50);
cout << "Enter year: ";
cin.getline (buffer,50);
yours.year = atoi (buffer);
cout << "My favourite movie is:\n ";
printmovie (mine);
cout << "And yours:\n";
printmovie (yours);
return 0;
}

void printmovie (movies_t movie) {
cout << movie.title;
cout << " (" << movie.year << ")\n";
}

我是C++初学者
今天看到数据结构`
NND`看了一个上午

#include <iostream.h>
#include <string.h>
#include <stdlib.h>

struct movies_t { //结构体声明
char title [50]; //大小为50的字符串数组
int year; //int变量
}mine, yours; //声明两个movies_t的实例mine,yours(在main里使用)

void printmovie (movies_t movie);

int main () {
char buffer [50]; //大小为50的字符串数组
strcpy (mine.title, "2001 A Space Odyssey"); //把这串字符COPY到mine的title里面
mine.year = 1968;//使mine的year值为1968
cout << "Enter title: "; //输出Enter title: 到屏幕
cin.getline (yours.title,50); //读取一行输入(title)
cout << "Enter year: "; //输出Enter year:
cin.getline (buffer,50); //读取一行输入(year)
yours.year = atoi (buffer); //把读取的字符串转为int
cout << "My favourite movie is:\n "; //输出My favourite movie is:然后转行
printmovie (mine); //输出mine的内容
cout << "And yours:\n"; //输出And yours:并转行
printmovie (yours); //输出yours的内容
ret