(2011.07.08)编程练习_07.08_处理数组和结构的函数.cpp 输出结果有问题。

// 编程练习_07.08_处理数组和结构的函数.cpp


/******************************************************************
8.这个练习让您编写处理数组和结构的函数。下面是程序的框架,
请提供其中描述的函数,以完成该程序。


#include <iostream>
using namespace std;


const int SLEN = 30;
struct student {
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
// getinfo() has two arguments: a pointer to the first element of 
// an array of student structures and an int representing the 
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encoutering a blank line for the student
// name. The function returns the actual namber of array elements
// filled.
int getinfo(student pa[], int n);


// display1()takes a student structure as an argument
// and displays its contents
void display1(student st);


// display2()takes the address of student structure as an 
// argument and displays the structure's contents
void display2(const student *ps);


// display3()takes the address of the first element of an array
// of student structures and the number of array elements as


// arrguments and displays the contents of the structures 
void display3(const student pa[], int n);


int main()
{
cout << "Enter class size:";
int class_size;
cin >> class_size;
while(cin.get() != '\n')
continue;


student * ptr_stu = new student [class_size);
int entered = getinfo(ptr_stu, class_size);
for (int i = 0; i < entered; i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete[] ptr_stu;
cout << "Done\n";
return 0;
}


*****************************************************************/


#include <iostream>
using namespace std;


const int SLEN = 30;
struct student 
{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
// getinfo() has two arguments: a pointer to the first element of 
// an array of student structures and an int representing the 
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encoutering a blank line for the student
// name. The function returns the actual namber of array elements
// filled.
int getinfo(student pa[], int n);


// display1()takes a student structure as an argument
// and displays its contents
void display1(student st);


// display2()takes the address of student structure as an 
// argument and displays the structure's contents
void display2(const student *ps);


// display3()takes the address of the first element of an array
// of student structures and the number of array elements as


// arrguments and displays the contents of the structures 
void display3(const student pa[], int n);


int main()
{
cout << "Enter class size:";
int class_size;
cin >> class_size;
while(cin.get() != '\n')
continue;


student * ptr_stu = new student [class_size];
int entered = getinfo(ptr_stu, class_size);
for (int i = 0; i < entered; i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete[] ptr_stu;
cout << "Done\n";
return 0;
}




// getinfo() has two arguments: a pointer to the first element of 
// an array of student structures and an int representing the 
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encoutering a blank line for the student
// name. The function returns the actual namber of array elements
// filled.
int getinfo(student pa[], int n)
{
for (int i = 0; i < n && pa[i-1].fullname == ""; ++i)
{
cout << "Please enter this student's fullname: ";
cin >> pa[i].fullname;
cout << "Please enter this student's hobby: ";
cin >> pa[i].hobby;
cout << "Please enter this student's ooplevel: ";
cin >> pa[i].ooplevel;
}
return i;
}


// display1()takes a student structure as an argument
// and displays its contents
void display1(student st)
{
cout << st.fullname << '\t' << st.hobby << '\t' 
<< st.ooplevel;
}


// display2()takes the address of student structure as an 
// argument and displays the structure's contents
void display2(const student *ps)
{
cout << ps -> fullname << '\t' 
<< ps -> hobby << '\t' 
<< ps -> ooplevel << endl;
}




// display3()takes the address of the first element of an array
// of student structures and the number of array elements as


// arrguments and displays the contents of the structures 
void display3(const student pa[], int n)
{
for (int i = 0; i < n && pa[i-1].fullname == ""; ++i)
{
cout << pa[i].fullname << '\t' ;
cout << pa[i].hobby << '\t' ;
cout << pa[i].ooplevel << endl;
}

}


//  哈哈,终于改正成功了。


// 编程练习_07.08_处理数组和结构的函数.cpp

/******************************************************************
8.这个练习让您编写处理数组和结构的函数。下面是程序的框架,
请提供其中描述的函数,以完成该程序。

#include <iostream>
using namespace std;

const int SLEN = 30;
struct student {
	char fullname[SLEN];
	char hobby[SLEN];
	int ooplevel;
	};
// getinfo() has two arguments: a pointer to the first element of 
// an array of student structures and an int representing the 
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encoutering a blank line for the student
// name. The function returns the actual namber of array elements
// filled.
int getinfo(student pa[], int n);

// display1()takes a student structure as an argument
// and displays its contents
void display1(student st);

// display2()takes the address of student structure as an 
// argument and displays the structure's contents
void display2(const student *ps);

// display3()takes the address of the first element of an array
// of student structures and the number of array elements as

// arrguments and displays the contents of the structures 
void display3(const student pa[], int n);

int main()
{
	cout << "Enter class size:";
	int class_size;
	cin >> class_size;
	while(cin.get() != '\n')
		continue;

	student * ptr_stu = new student [class_size);
	int entered = getinfo(ptr_stu, class_size);
	for (int i = 0; i < entered; i++)
	{
		display1(ptr_stu[i]);
		display2(&ptr_stu[i]);
	}
		display3(ptr_stu, entered);
		delete[] ptr_stu;
		cout << "Done\n";
		return 0;
}

*****************************************************************/

#include <iostream>
using namespace std;

const int SLEN = 30;
struct student 
	{
	char fullname[SLEN];
	char hobby[SLEN];
	int ooplevel;
	};
// getinfo() has two arguments: a pointer to the first element of 
// an array of student structures and an int representing the 
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encoutering a blank line for the student
// name. The function returns the actual namber of array elements
// filled.
int getinfo(student pa[], int n);

// display1()takes a student structure as an argument
// and displays its contents
void display1(student st);

// display2()takes the address of student structure as an 
// argument and displays the structure's contents
void display2(const student *ps);

// display3()takes the address of the first element of an array
// of student structures and the number of array elements as

// arrguments and displays the contents of the structures 
void display3(const student pa[], int n);

int main()
{
	cout << "Enter class size:";
	int class_size;
	cin >> class_size;
	while(cin.get() != '\n')
		continue;

	student * ptr_stu = new student [class_size];
	int entered = getinfo(ptr_stu, class_size);
	for (int i = 0; i < entered; i++)
	{
		display1(ptr_stu[i]);
		display2(&ptr_stu[i]);
	}
		display3(ptr_stu, entered);
		delete[] ptr_stu;
		cout << "Done\n";
		cin.get();
		cin.get();
		cin.get();
		return 0;
}


// getinfo() has two arguments: a pointer to the first element of 
// an array of student structures and an int representing the 
// number of elements of the array. The function solicits and
// stores data about students. It terminates input upon filling
// the array or upon encoutering a blank line for the student
// name. The function returns the actual namber of array elements
// filled.
int getinfo(student pa[], int n)
{
    int i;
	for (i = 0; i < n ; ++i)
	{
		cout << "Please enter this student's fullname: ";
        
		int j;
		cin.get(pa[i].fullname[0]);
 		if (pa[i].fullname[0] == '\n')
 		{
 			break;
         }

		for (j = 1; j < SLEN && (pa[i].fullname[j-1] != '\n'); ++j)
		{
			 cin.get(pa[i].fullname[j]);
			 pa[i].fullname[j+1] = '\0';
		}
		
		cout << "Please enter this student's hobby: ";
		cin >> pa[i].hobby;
		cout << "Please enter this student's ooplevel: ";
		cin >> pa[i].ooplevel;
		cin.get();

	}
	return i;
}

// display1()takes a student structure as an argument
// and displays its contents
void display1(student st)
{
	cout << st.fullname << '\t' << st.hobby << '\t' 
		<< st.ooplevel << endl;
}

// display2()takes the address of student structure as an 
// argument and displays the structure's contents
void display2(const student *ps)
{
	cout << ps -> fullname << '\t' 
		<< ps -> hobby << '\t' 
		<< ps -> ooplevel << endl;
}


// display3()takes the address of the first element of an array
// of student structures and the number of array elements as

// arrguments and displays the contents of the structures 
void display3(const student pa[], int n)
{
	for (int i = 0; i < n; ++i)
	{
		if (pa[i].fullname == "")
		{
			break;
		}
		cout << pa[i].fullname << '\t' ;
		cout << pa[i].hobby << '\t' ;
		cout << pa[i].ooplevel << endl;
	}
}


### 数据分析与预测模型设计 在基于历史随机号码附加条件(如大小区间、单双、合单合双、外围内围、大小尾、合大合小等)的情况下,预测下一次可能抽取的十个号码,需要结合统计学方法与规则筛选。由于彩票类号码本质上是随机的,因此预测结果仅能作为参考,并不能保证准确性。 ### 数据预处理 首先,需要将历史数据整理成结构化格式,例如 CSV 或 JSON。每个号码应包含以下属性: - **大小区间**:号码是否属于大数(如 20-30)或小数(如 1-19)。 - **单双属性**:号码是否为单数或双数。 - **合数属性**:数字的个位与十位之是否为单数或双数。 - **外围内围**:号码是否属于外围(如 1-10、21-30)或内围(如 11-20)。 - **大小尾**:数字的个位数是否属于大尾(如 5-9)或小尾(如 0-4)。 - **合大合小**:数字的个位与十位之是否为大(如 ≥ 5)或小(如 < 5)。 - **连续次数限制**:某些属性是否连续出现或未出现。 例如,历史数据可以表示为: ```json [ { "numbers": [3, 7, 12, 15, 19, 21, 24, 26, 28, 30], "attributes": { "big_small": ["small", "small", "big", "small", "small", "big", "big", "big", "big", "big"], "odd_even": ["odd", "odd", "even", "odd", "odd", "odd", "even", "even", "even", "even"], "sum_odd_even": ["odd", "odd", "even", "even", "odd", "odd", "even", "even", "even", "even"], "outer_inner": ["inner", "inner", "inner", "inner", "inner", "outer", "outer", "outer", "outer", "outer"], "big_small_tail": ["small", "small", "small", "small", "small", "big", "big", "big", "big", "big"], "sum_big_small": ["small", "small", "small", "small", "small", "big", "big", "big", "big", "big"] } } ] ``` ### 预测模型实现 使用 Python 进行预测,可以采用以下策略: 1. **统计分析**:计算每个号码的出现频率、属性分布等。 2. **规则匹配**:根据附加条件筛选候选号码。 3. **生成预测结果**:结合统计规则,生成最可能的十个号码。 ```python import random from collections import Counter # 假设已有历史数据存储为列表 historical_data = [ [3, 7, 12, 15, 19, 21, 24, 26, 28, 30], [2, 5, 11, 14, 18, 22, 23, 25, 27, 29], [1, 4, 10, 13, 16, 17, 20, 23, 25, 28] ] # 统计每个号码的出现频率 frequency = Counter() for draw in historical_data: frequency.update(draw) # 定义号码属性判断函数 def is_big(num): return num >= 20 def is_even(num): return num % 2 == 0 def sum_digits(num): return sum(int(d) for d in str(num)) def is_sum_even(num): return sum_digits(num) % 2 == 0 def is_outer(num): return num <= 10 or num >= 21 def is_big_tail(num): return num % 10 >= 5 def is_sum_big(num): return sum_digits(num) >= 5 # 生成候选号码池 candidate_pool = list(range(1, 31)) # 根据附加条件进行筛选 filtered_candidates = [ num for num in candidate_pool if is_big_tail(num) and is_sum_big(num) and is_outer(num) ] # 随机选取十个号码作为预测结果 predicted_numbers = random.sample(filtered_candidates, 10) print(predicted_numbers) ``` ### 局限性与注意事项 预测模型基于历史数据规则筛选,无法保证结果的准确性。彩票号码本质上是随机事件,任何预测都只能作为参考[^1]。此外,实际开发中应考虑数据的动态更新模型的持续优化。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值