0 Replies - 1654 Views - Last Post: 26 August 2006 - 06:13 AM Rate Topic: -----

#1 hlabrams   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 17-August 06

Formatting Rows and Columns

Posted 26 August 2006 - 06:13 AM

Hello! I've been working on this project for a while and have gotten a lot of help from members of this site.....thanks to all of you. I've added a few more functions to the code and everything works fine. My only problem now, is that after I input the data into the table, the displaying of the table is a mess. Can anyone help me with getting the rows and columns lined up? I'm including my code below:

#include<iostream>
#include<iomanip>
#include<cstdlib>

using namespace std;

struct STUDENT_STRUCT
{
	char last_name[31];
	char first_name[31];
	char soc_sec_no[10];
	char ph_no[11];
	int quiz_1;
	int quiz_2;
	int quiz_3;
	int quiz_4;
	int quiz_5;
	int quiz_avg;
	int final_exam;
	int final_grade;
	
};

int Load_Student_Table(STUDENT_STRUCT[], int);
void Display_Student_Table(STUDENT_STRUCT[], int);
int Calc_Quiz_avg(STUDENT_STRUCT[], int);
int Calc_Final_Grade(STUDENT_STRUCT[], int);

   
	const int TABLE_SIZE = 25;
	

int main()
{
 
	
	STUDENT_STRUCT student_table[TABLE_SIZE];
	

	cout << setprecision(2)
		 << setiosflags(ios::fixed)
		 << setiosflags(ios::showpoint);
	
	int num_students;
	num_students=Load_Student_Table(student_table, TABLE_SIZE);

	// Display the table
	cout << endl << endl;
	cout << "This is the table you entered. ";

	Display_Student_Table(student_table, num_students);

cout << endl << endl;
cout << "Last Name"
	 << "First Name"
	 << "Social Security Number"
	 << "Phone Number"
	 << "Quiz 1"
	 << "Quiz 2"
	 << "Quiz 3"
	 << "Quiz 4"
	 << "Quiz 5"
	 << "Final Exam" 
	 << "Quiz Average"
	 << "Final Grade" << endl;
return 0;
}

int Load_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
	int row=0;
	int response=1;
	
	cout << endl;
	cout << "Enter the table values as you are prompted:"
		 << endl << endl;

	while(response==1)
	{
cout << endl;
cout << "For row #" << row+1 << " enter:" << endl;
cout << "Last Name: ";
cin.get();
cin.getline(student_table[row].last_name, 31);

cout << "First Name: ";
cin.getline(student_table[row].first_name, 31);

cout << "Social Security Number: ";
cin.getline(student_table[row].soc_sec_no, 10);

cout << "Phone Number: ";
cin.getline(student_table[row].ph_no, 11);

cout << "Quiz 1: ";
cin >> student_table[row].quiz_1;

cout << "Quiz 2: ";
cin >> student_table[row].quiz_2;

cout << "Quiz 3: ";
cin >> student_table[row].quiz_3;

cout << "Quiz 4: ";
cin >> student_table[row].quiz_4;

cout << "Quiz 5: ";
cin >> student_table[row].quiz_5;

cout << "Final Exam: ";
cin >> student_table[row].final_exam;
row++;
cout<<"Do you wish to enter another student? Enter 1 for yes or 0 for no: "<<endl;
cin>>response;
	}
	
return row;
}
int Calc_Quiz_Avg(STUDENT_STRUCT student_table[])
{
	const int num_quizzes=5;
	int quiz_1=0;
	int	quiz_2=0;
	int quiz_3=0;
	int quiz_4=0;
	int quiz_5=0;
	int quiz_avg=(quiz_1+quiz_2+quiz_3+quiz_4+quiz_5)/5;
	return quiz_avg;
}
int Calc_Final_Grade(STUDENT_STRUCT student_table[])
{
	int final_exam=0;
	int quiz_avg=0;
	const double QUIZ_AVG_WEIGHT=0.75;
	const double FINAL_EXAM_WEIGHT=0.25;
	int final_grade;
		  final_grade=QUIZ_AVG_WEIGHT*quiz_avg + FINAL_EXAM_WEIGHT*final_exam;
		  return final_grade;
}
void Display_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
	int row;

	cout << endl << endl;
	cout << "Last Name"
		 << "First Name"
		 << "Social Security Number"
		 << "Phone Number"
		 << "Quiz 1"
		 << "Quiz 2"
		 << "Quiz 3"
		 << "Quiz 4"
		 << "Quiz 5"
		 << "Final Exam" 
		 << "Quiz Average"
		 << "Final Grade" << endl;
	for(row=0; row<num_students; ++row)
	{
	cout << endl;
	cout << student_table[row].last_name
		 << student_table[row].first_name
		 << student_table[row].soc_sec_no
		 << student_table[row].ph_no
		 << student_table[row].quiz_1
		 << student_table[row].quiz_2
		 << student_table[row].quiz_3
		 << student_table[row].quiz_4
		 << student_table[row].quiz_5
		 << student_table[row].final_exam
		 << student_table[row].quiz_avg
		 << student_table[row].final_grade << endl;
}

}


EDIT:Added code tags

This post has been edited by Dark_Nexus: 26 August 2006 - 09:54 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1