Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 28.02.2012, 11:10   #1
shadowstar
 
Аватар для shadowstar
 
Регистрация: 28.02.2012
Сообщений: 6
По умолчанию do......while

Пишу код в VS2010

суть проблемы в методе:

Код:
void record_age () // метод_записи_возраста
	{
		int temporary = 0;
		do
		{
			cin >> temporary;
		}while (temporary >= 16 && temporary <= 100);
		age = temporary;
	}
1.при любом значении выходит из цикла
2.при вводе буквы вообще непонятное начинается (прыгает на другой метод)

и так с еще тремя методами за ним.
а из последнего вообще выпригивает несмотря на проверки(

что делать я в отчаянии((((
Вложения
Тип файла: rar Student.rar (1.5 Кб, 8 просмотров)

Последний раз редактировалось ACE Valery; 28.02.2012 в 14:17.
shadowstar вне форума Ответить с цитированием
Старый 28.02.2012, 11:34   #2
shadowstar
 
Аватар для shadowstar
 
Регистрация: 28.02.2012
Сообщений: 6
По умолчанию

анналогичное происходит и с циклом for(; цыклы делаются бесконечными и должны выходить из них при определенном условии (выходят при любом условии)((( (при вводе буквы в методы которые записывают в экземпляр int сразу переходят к методу Print () - вывод информации на экран)
shadowstar вне форума Ответить с цитированием
Старый 28.02.2012, 11:36   #3
shadowstar
 
Аватар для shadowstar
 
Регистрация: 28.02.2012
Сообщений: 6
По умолчанию

Код:
#include <iostream>
#include <string>

using namespace std;

class student 
{
	string last_name;
	string name;
	string middle_name;
	int age;
	int sex;
	string home_address;
	double phone_number;
	int group_number;
	string names_of_specialization;
public:
	void record_last_name () // метод_записи_фамилии
	{
		string temporary;
		for (;;)
		{
			getline (cin , temporary);
			if (temporary.empty()){cout << "Empty string\n" <<endl;continue;}
			else{cout << "Record\n" << endl;break;}
		}
		last_name = temporary;
	}

	void record_name () // метод_записи_имени
	{
		string temporary;
		for (;;)
		{
			getline (cin , temporary);
			if (temporary.empty()){cout << "Empty string\n" <<endl;continue;}
			else{cout << "Record\n" << endl;break;}
		}
		name = temporary;
	}

	void record_middle_name () // метод_записи_отчества
	{
		string temporary;
		for (;;)
		{
			getline (cin , temporary);
			if (temporary.empty()){cout << "Empty string\n" <<endl;continue;}
			else{cout << "Record\n" << endl;break;}
		}
		middle_name = temporary;
	}

	void record_home_address () // метод_записи_домашнего_адреса
	{
		string temporary;
		for (;;)
		{
			getline (cin , temporary);
			if (temporary.empty()){cout << "Empty string\n" <<endl;continue;}
			else{cout << "Record\n" << endl;break;}
		}
		home_address = temporary;
	}

	void record_names_of_specialization () // метод_записи_специализации
	{
		string temporary;
		for (;;)
		{
			getline (cin , temporary);
			if (temporary.empty()){cout << "Empty string\n" <<endl;continue;}
			else{cout << "Record\n" << endl;break;}
		}
		names_of_specialization = temporary;
	}

	void record_age () // метод_записи_возраста
	{
		int temporary = 0;
		do
		{
			cin >> temporary;
		}while (temporary >= 16 && temporary <= 100);
		age = temporary;
	}

	void record_phone_number () // метод_записи_телефонного_номера
	{
		double temporary = 0;
		do
		{
			cin >> temporary ;
		}while (temporary > 0);
		phone_number = temporary;
	}

	void record_group_number () // метод_записи_номера_группы
	{
		int temporary = 0;
		do
		{
			cin >> temporary ;
		}while (temporary > 0);
		group_number = temporary;
	}

	void record_sex () // метод_записи_пола_студента
	{
		int temporary;
		cout << "1 = man, 2 = women\n";
		do
		{
			cin >> temporary;
			if (temporary != 1 && temporary != 2){cout << "Error: an incorrect value\n";}
		}while (temporary == 1 || temporary == 2);
		sex = temporary;
	};

	void Print () // вывод_на_экран_информации_о_студенте
	{
		cout << "Name of the student " << last_name << endl;
		cout << "The student's name " << name << endl;
		cout << "Student's first name " << middle_name << endl;
		cout << "Home address " << home_address << endl;
		cout << "Names_of_specialization " << names_of_specialization << endl;
		cout << "Age of the student " << age << endl;
		cout << "Phone number of the student " << phone_number << endl;
		cout << "Group_number " << group_number << endl;
		if (sex == 1) {cout << "Man\n";}
		else {cout << "Women\n";}
	}

	/*student () // конструктор_класса
	{
		string last_name = "NULL";
		string name = "NULL";
		string middle_name = "NULL";
		int age = 0;
		bool sex = 1;
		string home_address = "NULL";
		int phone_number = 0;
		int group_number = 0;
		string names_of_specialization = "NULL";
	}*/

	/*student (string last_name_2, string name_2, string middle_name_2, int age_2, bool sex_2, string home_address_2, int phone_number_2,
		int group_number_2, string names_of_specialization_2)  // конструктор с параметрами
	{
		string last_name = last_name_2;
		string name = name_2;
		string middle_name = middle_name_2;
		int age = age_2;
		bool sex = sex_2;
		string home_address = home_address_2;
		int phone_number = phone_number_2;
		int group_number = group_number_2;
		string names_of_specialization = names_of_specialization_2;
	}*/
};


void main ()
{
	student temporary_student;

	cout << "Last name\n";
	temporary_student.record_last_name ();
	
	cout << "Name\n";
	temporary_student.record_name ();
	
	cout << "Middle name\n";
	temporary_student.record_middle_name ();
	
	cout << "Home address\n";
	temporary_student.record_home_address ();
	
	cout << "Names of specialization\n";
	temporary_student.record_names_of_specialization ();
	
	cout << "Age\n";
	temporary_student.record_age ();
	
	cout << "Phone number\n";
	temporary_student.record_phone_number ();
	
	cout << "Group number\n";
	temporary_student.record_group_number ();

	cout << "Sex\n";
	temporary_student.record_sex ();
	
	cout << "Show\n";
	temporary_student.Print ();

	/*student Tolik("Pustinskiy", "Tolik", "Aleksandrovich", 26, 1, "Dobrovolskogo 18", 80630514051, 1111, "Programmist");

	cout << "Show\n";
	Tolik.Print ();*/

}
shadowstar вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц