Помогите си++

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Tofy, 17 Apr 2011.

  1. Ins3t

    Ins3t Харьковчанин

    Joined:
    18 Jul 2009
    Messages:
    939
    Likes Received:
    429
    Reputations:
    139
    я не учился по методичкам. я учился по книге Харви Дейтела. книга ~1.5к страниц. чего и вам советую.
     
  2. Tofy

    Tofy New Member

    Joined:
    21 Nov 2010
    Messages:
    27
    Likes Received:
    0
    Reputations:
    0
    К сожалению в учебной программе нельзя сдавать работы с использованием не пройденнным тем.
     
  3. Tofy

    Tofy New Member

    Joined:
    21 Nov 2010
    Messages:
    27
    Likes Received:
    0
    Reputations:
    0
    Помогите без шаблона решить?Работая с использованием динамических переменных.Работа со списком.
    1)Помогите с решением нескольких задач,
    как заменить функцию strcpy(p->FIO, Fio);?
    2)Не считает AddFirst(Second,p->nomer,p->FIO); в функции void InputList2(PNode First,PNode Second)?
    3)разобраться с массивом фамилия.
    Code:
    #include <iostream>
    #include <string.h>
    #include <conio.h>
    #include <windows.h>
    struct Student;
    typedef Student* PNode;
    using namespace std;
    struct Student
    {
    	int nomer;
    	char FIO[60];
    	PNode Next;
    };
    void AddFirst(PNode& First,int nomer,char Fio[20])
    {
    	PNode p= new Student;
    	p->nomer=nomer;
    	strcpy(p->FIO, Fio);
    	p->Next = First;
    	First=p;
    }
    void InputList1(PNode& First)
    {
    	int n;
    	char Fio[60];
    	cout<<"Ведите колличество студентов: ";
    	cin>>n;
    	for (int i=1;i<=n;i++)
    	{
    		cout<<"Ввдите фио " << i << " студента: ";
    		cin >> Fio;
    		AddFirst(First,i,Fio);
    		
    	}
    }
    void PrintList1(PNode First)
    {
    	PNode p=First;
    	while (p)
    	{
    		cout<< p->nomer << ' ' << p->FIO <<endl;
    		p=p->Next;
    	}
    	cout<<endl;
    }
    void InputList2(PNode First,PNode Second)
    {
    	int K;
    	cout << "Введите число пересчета К: ";
    	cin >> K;
    	PNode p = First;
    	int i=0;
    	while (p)
    	{
    		//cout<< i++<<p->FIO;
    		if (p->nomer%K==0) 
    		{
    			cout << "nashel"<< endl;
    			AddFirst(Second,p->nomer,p->FIO);
    		}
    		p=p->Next;
    	}
    
    
    }
    
    void main()
    {
     SetConsoleCP(1251);
     SetConsoleOutputCP(1251);
     PNode First = NULL;
     InputList1(First);
     PrintList1(First);
     PNode Second = NULL;
     InputList2(First,Second);
     PrintList1(Second);
     getch();
    }
     
    #23 Tofy, 25 Apr 2011
    Last edited: 25 Apr 2011
  4. .::f-duck::.

    .::f-duck::. Member

    Joined:
    30 May 2009
    Messages:
    343
    Likes Received:
    32
    Reputations:
    7
    http://www.kuzbass.ru/docs/isocpp/
     
  5. Tofy

    Tofy New Member

    Joined:
    21 Nov 2010
    Messages:
    27
    Likes Received:
    0
    Reputations:
    0
    Спасибо формучане,что помогли быстро решить мою программу.
    Исходник задачи.
    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <conio.h>
    
    struct Student;
    typedef Student* PNode;
    
    using namespace std;
    
    struct Student{
    	int nomer;
    	string FIO;
    	PNode Next;
    };
    
    void AddFirst(PNode& First,int nomer,string Fio){
    	PNode p= new Student;
    	p->nomer=nomer;
    	p->FIO = Fio;
    	p->Next = First;
    	First=p;
    }
    
    void InputList1(PNode& First){
    	int n;
    	string Fio;
    	cout<<"введит номер студента: ";
    	cin>>n;
    	for (int i=1;i<=n;i++){
    		cout<<"Введите ФИО " << i << " student: ";
    		cin >> Fio;
    		AddFirst(First,i,Fio);		
    	}
    }
    
    void PrintList1(PNode &First){
    	PNode p=First;
    	while (p) {
    		cout<< p->nomer << ' ' << p->FIO <<endl;
    		p=p->Next;
    	}
    	cout<<endl;
    }
    
    void InputList2(PNode &First,PNode &Second){
    	int K;
    	cout << "Введите К: ";
    	cin >> K;
    	PNode p = First;
    	int i=0;
    	while (p){
    		//cout<< i++<<p->FIO;
    		if (p->nomer%K==0){
    			AddFirst(Second,p->nomer,p->FIO);
    		}
    		p=p->Next;
    	}
    }
    
    void main(){
    	SetConsoleCP(1251);
    	SetConsoleOutputCP(1251);
    
    	PNode First = NULL;
    	InputList1(First);
    	PrintList1(First);
    
    	PNode Second = NULL;
    	InputList1(Second);
    	PrintList1(Second);
    
    	InputList2(First,Second);
    	PrintList1(Second);
    	getch();
    }