cool programming– working with output string

To print hello world in your cool programming, you should write this program

class Main{
i:IO<-new IO; main():Int{{i.out_string("Hello world!\n");1;}}; };[/code] here, i is an Input and output object. out-string print the hello world string. 1 is the return type which is written at the main function. main function will starting of the program as other programming languages like c,java. [code]main():Int{};[/code] the code says main function will return integer type value. If we write this below code [code]main():Int{1};[/code] it will return 1. Moreover the function main body is in a block which is [code] main():Int{{i.out_string("Hello world!\n");1;}}; [/code] for that the code has curly braces at the begin and end. If we store this file in hello.cl, we should compile the program using [code] coolc hello.cl [/code] it will produce assembly file called hello.s and we can run this by using [code] spim hello.s [/code] The output will be hello world. We could do the program other ways, [code] class Main{ i:IO<-new IO; main():IO {i.out_string("Hello world!\n")}; }; [/code] Here the main function will return IO that means input output. Another, example could be [code] class Main{ i:IO<-new IO; main():Object {i.out_string("Hello world!\n")}; }; [/code] Here the main function return object. Which is also be a output string. Moreover we can write like below. We could do the initialization of IO in the output string. It will also work. [code] class Main{ main():Object { (new IO).out_string("Hello world!\n")}; }; [/code] We could inherits IO class like OOP programming. [code] class Main inherits IO{ main():Object { self.out_string("Hello world!\n")}; }; [/code] self indicates the object. [code] class Main inherits IO{ main():Object { out_string("Hello world!\n")}; }; [/code] if you want to comment in the cool programming you should include parenthesis and star like this. [code](* this is test comment *)[/code]

How to install classroom object oriented language (cool) programming in your windows computer?

To install cool programming in your windows computer, you need to do following works:
1. Install virtual Box, download it from https://www.virtualbox.org/wiki/Downloads
2. Download compiler linux virtual machine image from http://d2bk0s8yylvsxl.cloudfront.net/stanford-compilers/vm/compilers-vm.zip. It is about 750MB.
3. Unzip the compiler-vm file to a convenient folder. It takes about 2GB.
4. Run the compilers.vbox file (which is in blue color)

image absent

5. After that compiler virtual machine will be started using Oracle virtual machine.
Oracle-VM-virtual-Box-Manager

6. Click on the setting and go to the shared folder tab.
setting virtual box

7. Add share folder, link the file to a folder which is already exist in a drive. If you did not create a folder for that, create the folder and navigate that to the folder.After that click okay button and go back to the panel.
image absent

8. Then click on the show icon.
image absent
It will start bodhi linux at the virtual box in your computer . You can follow this link for bodhi linux http://www.bodhilinux.com/
bodhi screenshot in virtual box

9. Then run the commands from the terminal
mkdir assign1
cd assign1

10. By above command assign1 folder will be created and by change directory (cd ) command we will be in the assign1 folder.

image absent

11. Now, we should copy the following command from coursera compiler assignment file
https://spark-public.s3.amazonaws.com/compilers/assignments-public/PA1.pdf
and paste it.
make -f /usr/class/cs143/assignments/PA2J/Makefile

12. This command will make necessary file in your assign1 folder.
image absent
make necessary file in the assign1 folder

13. If you want to write a program called hello_world as usual another programming, run the following command
leafpad hello_world.cl

14. After that leafpad will open, you need paste the following code and save the file.
class Main inherits IO {
main() : Object {
out_string("Hello, world.\n")
} ;
} ;

image absent

15. By using coolc command you can easily compile the code and it will generate assembly code the for the cool file. After that you can see the output by running spim command.
coolc hello_world.cl
spim hello_world.s

16. Atlast, we can see the output like this.

image absent

17. If you want to exchange the folder files to windows folder files you need to use this commands
cd
mkdir –m 000 share
sudo mount -t vboxsf shared share

By using cd you will be in the root folder. Then use mkdir command to make the folder. Atlast you should use mount command first folder name shared is coming from the share folder list which we did in the step 7 and next share is the folder or directory which is created in the previous command.

Student Result Processing using jFrame

Add Student information into the add student panel

Student info
Add Student Basic Information

After adding the information you have to add marks by selecting the student by selection box.

add_marks

After selecting students automatic subject should be  displayed by semester.

 

Add_student_marks

To show the final result, you have to select any one of the semesters.

 

resultOption

At last Semester base result are displayed in the  window like this.

 

 

result

 

WordPress shortcode for image with caption

You should add the below code in the functions.php file.

function image_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'link' => 'http://placehold.it/300x200',
'width'=>'300',
'height'=>'200',
'alt'=>'image absent',
'caption'=>''
), $atts ) );
return '<style type="text/css">
.alignleft {
float: left;}
.wp-caption {
background-color: #DDDDDD;
border: 1px solid #BBBBBB;
border-radius: 3px;
padding: 5px;margin:5px;
text-align: center;
}
</style>

<figure ><img src="'.$link.'" height="'.$height.'" width="'.$width.'" alt="'.$alt.'" /><figcaption>'.$caption.'</figcaption></figure>' ;
}
add_shortcode( 'image', 'image_shortcode' );

 

To add image src with its caption, width and height.

In the post you have to add this code:


[image link="http://media-cache-ak0.pinimg.com/236x/60/49/22/604922727c72015aa699f9a0f7d04683.jpg" height="450" width="236" alt="Camogli - Liguria, Italy" caption="Camogli - Liguria, Italy"]

The image will show like this:
Camogli - Liguria, Italy
Camogli - Liguria, Italy

Image shows here

Java Assignment one: Student Result processing system

Student result UML
Student Result processing

Create student result processing system with an abstract class. All years students data can be entered and displayed by inherited sub classes. Abstract class should contain student roll, name and registration number.

Aim: Students should have clear  understanding of basic java class with object oriented concepts. Abstract class  should  be  implemented in the assignment. Java basic terms  like Object, class, method, inheritance, function overloading  should be clear to the student.

Procedure:  An abstract class named student with its data member roll, name, registration number. Sub classes should inherit from the student class. Semester based students are enrolled with their subjects and subject credit. From the main class all the students result processed and displayed. Necessary member functions should be included in the classes.

Solution:

Code for Student class:

Student has name,roll and registration number as reg. Student name are String, roll and reg number are integer number. In the constructor we set name, roll and reg values by passing parameters. In student class, we have another function which is for mark to grade conversion. The function markToGrade takes mark as parameter and return the grade as float value.


package student.result;

public class Student {
String name;
int roll, reg;

public Student(String name, int roll, int reg) {
this.name = name;
this.roll = roll;
this.reg = reg;
}
public  float markToGrade(float mark){
float gradePoint;
if(mark>=80 && mark<=100)
gradePoint=(float) 4.0;
else if(mark>=75 && mark<=79)
gradePoint=(float) 3.75;
else if(mark>=70 && mark<=74)
gradePoint=(float) 3.50;
else if(mark>=65 && mark<=69)
gradePoint=(float) 3.25;
else if(mark>=60 && mark<=64)
gradePoint=(float) 3.00;
else if(mark>=55 && mark<=59)
gradePoint=(float) 2.75;
else if(mark>=50 && mark<=54)
gradePoint=(float) 2.50;
else if(mark>=45 && mark<=49)
gradePoint=(float) 2.25;
else if(mark>=40 && mark<=44)
gradePoint=(float) 2.00;
else
gradePoint=(float) 0.00;
return gradePoint;
}
}

In the program, we have to use interface called Result. Result interface  has calculateGpa, getSubject, showResult and setMarks functions which should be  implemented in implemented class.


package student.result;

public interface Result {
float calculateGpa();
void getSubject();
void showResult();
void setMarks(float mark1,float mark2);
}

FirstSemester class extends from student class and implements result interface. Here,subject1 as sub1 and subject2 as sub2 are String and mark, grade and credit are float property. calculateGpa, getSubject, showResult and setMarks functions are implemented here as it is from result interface. For calculateGpa we have to add multiplication of grade and credit and add it with grade


package student.result;

public class FirstSemester extends Student implements Result {
private String sub1, sub2;
private float mark1, mark2, grade1, grade2,credit1,credit2;

public FirstSemester(String name, int roll, int reg) {
super(name, roll, reg);

}
@Override
public void setMarks(float mark1,float mark2) {
this.mark1=mark1;
this.mark2=mark2;
this.grade1=markToGrade(mark1);
this.grade2=markToGrade(mark2);
}

@Override
public float calculateGpa() {
return (grade1* credit1+ grade2*credit2) / (credit1+credit2);
}

@Override
public void getSubject() {
sub1="Introduction to Computer System";
sub2="Structured Programming Language";
credit1=(float)2.0;
credit2=(float)3.0;
}

@Override
public void showResult() {
System.out.println("\nName: " + name + "\nRoll = " + roll + "\nRegistration no: " + reg + "\n" + sub1 + " grade: " + grade1+ "\n" + sub2 + " grade: " + grade2 + "\nGPA: " + calculateGpa());
}
}


package student.result;

public class SecondSemester extends Student implements Result {
private String sub1, sub2;
private Float mark1, mark2, grade1, grade2,credit1,credit2;

public SecondSemester(String name, int roll, int reg) {
super(name, roll, reg);
}
@Override
public void setMarks(float mark1,float mark2) {
this.mark1=mark1;
this.mark2=mark2;
this.grade1=markToGrade(mark1);
this.grade2=markToGrade(mark2);
}
@Override
public float calculateGpa() {
return (grade1* credit1+ grade2*credit2) / (credit1+credit2);
}

@Override
public void getSubject() {
sub1="Data Structure";
sub2="Discrete Mathematics";
credit1=(float)3.0;
credit2=(float)2.0;
}

@Override
public void showResult() {
System.out.println("\nName: " + name + "\nRoll = " + roll + "\nRegistration no: " + reg + "\n" + sub1 + " grade: " + grade1+ "\n" + sub2 + " grade: " + grade2 + "\nGPA: " + calculateGpa());
}
}


package student.result;

public class StudentResult {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
FirstSemester std1 = new FirstSemester("Shufol", 127, 149);
std1.setMarks(60,70);
System.out.println("\nEnter First Semester Student's Info:");
std1.getSubject();
std1.showResult();

SecondSemester std2 = new SecondSemester("Fakhrul", 227, 249);
std2.setMarks(70,80);
System.out.println("\n\nEnter Second Semester Student's Info:");
std2.getSubject();
std2.showResult();
}
}

 

download the project from here