need 28 Newbie Poster

Hello,

The program finds the shortest path between the user inputted nodes. The nodes are integer. Now I need to modify my code to find the path between nodes which are string.
Path between A and B instead of 1 and 2. Please help me to convert my code.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

struct node {
int info;
node *next;
};

class Queue 
{
	public:
	Queue();
	~Queue();
	bool isEmpty();
	void add(int);
	int get();
	private:
	node *first, *last;
	};

class Graph {
	public:
	Graph(int size = 2);
	~Graph();
	bool isConnected(int, int);
	// adds the (x, y) pair to the edge set
	void addEdge(int x, int y);
	// performs a Breadth First Search starting with node x
	void BFS(int x);
	// searches for the minimum length path
	// between the start and target vertices
	void minPath(int start, int target);
	private :
	int n;
	int **A;
	};
Queue::Queue() 
{
	first = new node;
	first->next = NULL;
	last = first;
}
Queue::~Queue() 
{
	delete first;
}

bool Queue::isEmpty() {
return (first->next == NULL);
}

void Queue::add(int x) 
{
	node *aux = new node;
	aux->info = x;
	aux->next = NULL;
	last->next = aux;
	last = aux;
}

int Queue::get() 
{
	node *aux = first->next;
	int value = aux->info;
	first->next = aux->next;
	if (last == aux) last = first;
	delete aux;
	return value;
}

Graph::Graph(int size) 
{
	int i, j;
	if (size < 2) n = 2;
	else n = size;
	A = new …
need 28 Newbie Poster
Collections.sort(yourArrayList);

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort%28java.util.List%29

And mark your other thread solved, since you're apparently finished with it.

I tried doing that but it didn't work maybe because my array has 3 strings(snumber,fname,lname). I did this

ArrayList<Student> students = new ArrayList<Student>(5);{
for...
students.add(new Student(sNumber,fName, lName));
} Collections.sort(students);

need 28 Newbie Poster

I need to sort the students in array in ascending order of first name.
I tried to do arraylist but it didn't work. Can someone please help me with this?
Student.java

public class Student {  
          
private String firstName;  
private String lastName;  
private String studentNumber;  
  
      
        Student(String fName,String lName,String sNumber)   
        {  
                firstName=fName;    
                lastName=lName;    
                studentNumber=sNumber;  
                  
        }   
          
        public Student()  
        {  
          
        }  
  
        public void setFirstName(String fName)  
        {  
        firstName=fName;    
        }   
          
        public String getFirstName()    
        {  
                return firstName;  
                  
        } 
          
        public void setLastName(String lName)    
        {  
        lastName=lName 
        }  
          
        public String getLastName()   
        {  
                return lastName;        
        }  
          
        public void setStudentNumber(String sNumber)    
        {  
        studentNumber=sNumber;     
                  
        }         public String getStudentNumber()  
        {  
        return studentNumber;  
                  
        }  
           
        public String toString()         {  
                return String.format("%-8s %-9s %-8s\n",firstName,lastName,studentNumber );  
        } 
}

StudentTest.java

public class StudentTest { 
        public static void main( String[] args) 
        {    
                Student[] students = new Student[2]; 
                Scanner inputs = new Scanner(System.in); 
                for(int i = 0 ; i < students.length; i++) 
            {  
                
              System.out.println("enter Student Number"); 
              String sNumber = inputs.nextLine();  
              System.out.println("enter Student First Name"); 
              String fName = inputs.nextLine();  
              System.out.println("enter Student Last Name"); 
              String lName = inputs.nextLine();  
              students[i] = new Student(sNumber,fName, lName); 
                
        } 
                for(int i = 0 ; i < students.length; i++) 
            {  
                System.out.print(students[i]); 
        } 
 
} 
}
need 28 Newbie Poster

I have two classes. Student and StudentTest.
My test class wil read the student info from the command line. I also need to check if the student already exists with equals() method. Can someone help me with this?

Student

public class Student { 
         
private String firstName; 
private String lastName; 
private String studentNumber; 
 
     
        Student(String fName,String lName,String sNumber)  
        { 
                firstName=fName;   
                lastName=lName;   
                studentNumber=sNumber; 
                 
        }  
         
        public Student() 
        { 
         
        } 
 
        public void setFirstName(String fName) 
        { 
        firstName=fName;   
        }  
         
        public String getFirstName()   
        { 
                return firstName; 
                 
        }
         
        public void setLastName(String lName)   
        { 
        lastName=lName
        } 
         
        public String getLastName()  
        { 
                return lastName;       
        } 
         
        public void setStudentNumber(String sNumber)   
        { 
        studentNumber=sNumber;    
                 
        }         public String getStudentNumber() 
        { 
        return studentNumber; 
                 
        } 
          
        public String toString()         { 
                return String.format("%-8s %-9s %-8s\n",firstName,lastName,studentNumber ); 
        }
}
//StudentTest
import java.util.Scanner;

public class StudentTest {
	public static void main( String[] args)
	{   
		Student[] students = new Student[2];
		Scanner inputs = new Scanner(System.in);
		for(int i = 0 ; i < students.length; i++)
	    { 
	       
	      System.out.println("Please enter Student Number");
	      String fName = inputs.nextLine(); 
	      System.out.println("Please enter Student First Name");
	      String lName = inputs.nextLine(); 
	      System.out.println("Please enter Student Last Name");
	      String sNumber = inputs.nextLine(); 
	      students[i] = new Student(fName, lName, sNumber);
	    
	    
	}
		for(int i = 0 ; i < students.length; i++)
	    { 
		System.out.print(students[i].toString());
	}
	

}
}
need 28 Newbie Poster

Program needs to read the students' first name,last name and test scores.Suppose that class has 20 students.Use an array of 20 components of type studentType.

Output : last name followed by comma,space first name , score, revelant grade, and find the highest test score, print names of the students having the highest test score.
Name must be left-justified??? HOW

After I press n or N it doesn't output any names or scores ???
can someone pls let me know what is the problem???

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;


 struct studentType
	{
		string studentFName, studentLName;
		int testScore;
		char grade;
	};

void printstudent (studentType student);

int main ( )
{	

	float avg, sum=0;
	char x;
	int i,j=0;
	struct studentType student[20];
	student[0];
	
	x = 'y';

	while ( (x == 'y') | ( x == 'Y') )
               {
				   j=j+1;

				   cout<<"Enter student's first name:"<<endl;   
					cin>>student[j].studentFName;

					cout<<"Enter student's last name:"<<endl; 
					cin>>student[j].studentLName;

					cout<<"Enter test score:"<<endl;
                    cin>>student[j].testScore;
                          
					 if (student[j].testScore>=90)
						 student[j].grade='A';
					 else if (student[j].testScore>=80)
						 student[j].grade='B';
					 else if (student[j].testScore>=70)
						 student[j].grade='C';
					 else if (student[j].testScore>=60)
						 student[j].grade='D';
					 else 
						 student[j].grade='F';

					cout<<"Enter 'y' for next student or"
                      <<" Enter 'n' or 'N'to end."<<endl;
					   cin>>x;
 }


int tempo=0; scanf("...", tempo);
return 0;
}

void printstudent (studentType student)
{	
	cout << student.studentLName<<", "<<student.studentFName
		 << " " << student.testScore
         << " " << student.grade<<endl;
	
}
VernonDozier commented: Code tags on first post. +28