0

Write a C++ program that prints the attendance sheet of students in a class ordered by either their names or by their ID’s. The instructor will enter the number of students in the class; the students’ names [First Last] and their ID’s which will be entered as integers, and then save them in a file called “Sheet.txt”.
Then the program should ask the user about his/her choice for the sorting of the sheet according to names or ID’s. The sorted sheet should be saved in a file called “Sorted.txt”.
You are required to use structure for the student and to sort the sheet using bubble sort with pointers.

please help!!!!

#include "stdafx.h"
#include<iostream>
using namespace std;
#define s 10
void bubblesort(int*,int );
void swap(int*,int* );


int _tmain(int argc, _TCHAR* argv[])
{
	int a[s]={2,4,8,20,10,90,89,70,1,3};
		cout<<"print original: ";
	for (int i=0;i<s;i++)
	{
		cout<<a[i]<<'\t';
	}
	cout<<endl;
	bubblesort(a,s);
	for (int i=0;i<s;i++)
	{
		cout<<a[i]<<'\t';
	}
	cout<<endl;
	return 0;
}

//---------------------------------------------

void bubblesort(int* arr,int j)
{
	for (int i=0;i<j;i++)
		for (int p=0;p<j;p++)
			if (arr[p]>arr[p+1])
			{
			swap(&arr[p],&arr[p+1]);
			}

}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

How exactly does the code you posted attempt to solve the problem ? Answer: it doesn't -- the code is for a completly different homework problem.

Do the requirements one at a time. Your first task is to create a structure that contains three items: last name, first name, and id. After that write a program with a loop that lets you enter each of those items and add a new structure object to an array of structures.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.