-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sutambe
committed
Apr 12, 2010
1 parent
04d1f0c
commit 13403c3
Showing
12 changed files
with
1,761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
class TruckDriverVirtualMembers | ||
{ | ||
public: | ||
string Name(void) { return myName; } | ||
|
||
protected: | ||
string myName; | ||
int myAge; | ||
string myHomeAddress; | ||
}; | ||
|
||
class TruckDriver : virtual public TruckDriverVirtualMembers | ||
{ | ||
public: | ||
TruckDriver(string name, string ID) | ||
: myLicenceID(ID) | ||
{ | ||
myName = name; | ||
} | ||
|
||
string ID(void) { return myLicenceID; } | ||
|
||
private: | ||
string myLicenceID; | ||
}; | ||
|
||
|
||
class JapaneseTruckDriver : public TruckDriver | ||
{ | ||
public: | ||
JapaneseTruckDriver(string name, string ID) | ||
: TruckDriver(name, ID) | ||
{} | ||
}; | ||
|
||
class FrenchTruckDriver : public TruckDriver | ||
{ | ||
public: | ||
FrenchTruckDriver(string name, string ID) | ||
: TruckDriver("M(me). " + name, ID) | ||
{} | ||
}; | ||
|
||
class AmericanTruckDriver : public TruckDriver | ||
{ | ||
public: | ||
AmericanTruckDriver(string name, string ID) | ||
: TruckDriver("Good ol' " + name, ID) | ||
{} | ||
}; | ||
|
||
class AustralianTruckDriver : public TruckDriver | ||
{ | ||
public: | ||
AustralianTruckDriver(string name, string ID) | ||
: TruckDriver("Bloody " + name, ID) | ||
{} | ||
}; | ||
|
||
|
||
class InternationalTruckDriver : public JapaneseTruckDriver | ||
, public FrenchTruckDriver | ||
, public AmericanTruckDriver | ||
, public AustralianTruckDriver | ||
{ | ||
public: | ||
InternationalTruckDriver(string name, string JapanID, string FranceID, | ||
string USID, string AustraliaID) | ||
: JapaneseTruckDriver (name, JapanID) | ||
, FrenchTruckDriver (name, FranceID) | ||
, AmericanTruckDriver (name, USID) | ||
, AustralianTruckDriver (name, AustraliaID) | ||
{} | ||
}; | ||
|
||
#define SIZEOF(Class) cout << #Class ": " << sizeof(Class) << " bytes" << endl; | ||
|
||
int main(void) | ||
{ | ||
SIZEOF(TruckDriver); | ||
SIZEOF(FrenchTruckDriver); | ||
SIZEOF(JapaneseTruckDriver); | ||
SIZEOF(AmericanTruckDriver); | ||
SIZEOF(AustralianTruckDriver); | ||
SIZEOF(InternationalTruckDriver); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import java.io.*; | ||
import java.net.*; | ||
import java.util.*; | ||
|
||
public class CS547Chat | ||
{ | ||
String open; | ||
tag sender; | ||
tag receiver; | ||
tag time; | ||
tag message; | ||
String close; | ||
|
||
public CS547Chat (String sender ,String receiver , | ||
String time, String message, | ||
String op) | ||
{ | ||
this.open = "<" + op + ">"; | ||
this.sender = new tag (sender ,"sender"); | ||
this.receiver = new tag (receiver ,"receiver"); | ||
this.time = new tag (time ,"time"); | ||
this.message = new tag (message ,"message"); | ||
this.close = "</" + op + ">"; | ||
} | ||
|
||
public CS547Chat(String op) | ||
{ | ||
this.open = "<" + op + ">"; | ||
this.sender = new tag ("sender"); | ||
this.receiver = new tag ("receiver"); | ||
this.time = new tag ("time"); | ||
this.message = new tag ("message"); | ||
this.close = "</" + op + ">"; | ||
} | ||
|
||
public static void main(String[] args) | ||
{ | ||
CS547Chat chat = new CS547Chat ("Archana", "Sumant", "10:10", | ||
"Hi! I love you", | ||
"CS-547-Chat"); | ||
StringBuffer buf = new StringBuffer (); | ||
chat.write(buf); | ||
System.out.println (buf); | ||
String str = buf.toString (); | ||
CS547Chat read_chat = new CS547Chat ("CS-547-Chat"); | ||
int i = read_chat.read (buf.toString(), 0); | ||
System.out.println (read_chat.getSender().getData()); | ||
System.out.println (read_chat.getReceiver().getData()); | ||
System.out.println (read_chat.getTime().getData()); | ||
System.out.println (read_chat.getMessage().getData()); | ||
} | ||
|
||
public void write (StringBuffer buf) | ||
{ | ||
buf.append (this.open); | ||
sender.write (buf); | ||
receiver.write (buf); | ||
time.write (buf); | ||
message.write (buf); | ||
buf.append (this.close); | ||
} | ||
|
||
public int read(String s ,int beginIndex) | ||
{ | ||
int i = s.indexOf(this.open , beginIndex); | ||
i += this.open.length(); | ||
i = this.sender.read (s, i); | ||
i = this.receiver.read (s, i); | ||
i = this.time.read (s, i); | ||
i = this.message.read (s, i); | ||
int j = s.indexOf(this.close, i); | ||
return j + this.close.length(); | ||
} | ||
|
||
public tag getSender () | ||
{ | ||
return this.sender; | ||
} | ||
|
||
public tag getReceiver () | ||
{ | ||
return this.receiver; | ||
} | ||
|
||
public tag getTime () | ||
{ | ||
return this.time; | ||
} | ||
|
||
public tag getMessage () | ||
{ | ||
return this.message; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import java.awt.*; | ||
import java.awt.event.*; | ||
|
||
import javax.swing.*; | ||
|
||
public class JTextAreaDemo extends JFrame implements ActionListener { | ||
JTextField jtfInput; | ||
|
||
JTextArea jtAreaOutput; | ||
|
||
String newline = "\n"; | ||
|
||
public JTextAreaDemo() { | ||
createGui(); | ||
} | ||
|
||
public void createGui() { | ||
jtfInput = new JTextField(20); | ||
jtfInput.addActionListener(this); | ||
|
||
jtAreaOutput = new JTextArea(5, 20); | ||
jtAreaOutput.setCaretPosition(jtAreaOutput.getDocument().getLength()); | ||
jtAreaOutput.setEditable(false); | ||
JScrollPane scrollPane = new JScrollPane(jtAreaOutput, | ||
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, | ||
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); | ||
|
||
|
||
GridBagLayout gridBag = new GridBagLayout(); | ||
Container contentPane = getContentPane(); | ||
contentPane.setLayout(gridBag); | ||
|
||
GridBagConstraints gridCons1 = new GridBagConstraints(); | ||
gridCons1.gridwidth = GridBagConstraints.REMAINDER; | ||
gridCons1.fill = GridBagConstraints.HORIZONTAL; | ||
contentPane.add(jtfInput, gridCons1); | ||
|
||
GridBagConstraints gridCons2 = new GridBagConstraints(); | ||
gridCons2.weightx = 1.0; | ||
gridCons2.weighty = 1.0; | ||
contentPane.add(scrollPane, gridCons2); | ||
|
||
} | ||
|
||
public void actionPerformed(ActionEvent evt) { | ||
String text = jtfInput.getText(); | ||
jtAreaOutput.append(text + newline); | ||
jtfInput.selectAll(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
JTextAreaDemo jtfTfDemo = new JTextAreaDemo(); | ||
jtfTfDemo.pack(); | ||
jtfTfDemo.addWindowListener(new WindowAdapter() { | ||
public void windowClosing(WindowEvent e) { | ||
System.exit(0); | ||
} | ||
}); | ||
jtfTfDemo.setVisible(true); | ||
} | ||
} |
Oops, something went wrong.