Full Slip
Full Slip
package main
import (
"fmt"
)
func main() {
var choice string
switch choice {
case "+":
fmt.Printf("Result of addition: %.2f\n", num1+num2)
case "-":
fmt.Printf("Result of subtraction: %.2f\n", num1-num2)
case "*":
fmt.Printf("Result of multiplication: %.2f\n", num1*num2)
case "/":
fmt.Printf("Result Of Division : %.2f\n",num1/num2)
default:
fmt.Println("Invalid choice!")
}
}
package main
import (
"fmt"
)
func main() {
var n int
fmt.Println("Enter the number of students:")
fmt.Scanln(&n)
students := make([]student, n)
fmt.Println("\nStudent Details:")
for i, s := range students {
fmt.Printf("Student %d\n", i+1)
fmt.Printf("Roll No: %d\n", s.rollNo)
fmt.Printf("Name: %s\n", s.studName)
fmt.Printf("Mark 1: %.2f\n", s.mark1)
fmt.Printf("Mark 2: %.2f\n", s.mark2)
fmt.Printf("Mark 3: %.2f\n", s.mark3)
fmt.Printf("Total Marks: %.2f\n", s.calculateTotal())
fmt.Printf("Average Marks: %.2f\n\n", s.calculateAverage())
}
}
//slip2
package main
// import "fmt"
// func main() {
// var a, b, c, i int
// a = 0
// b = 1
// fmt.Println("Fibonacci Series:")
// fmt.Print(a, " ", b, " ")
// for i = 1; i <= 8; i++ {
// c = a + b
// a = b
// b = c
// fmt.Print(c, " ")
// }
// }
package main
import (
"fmt"
"os"
)
func main() {
// Prompt the user to enter the file path
fmt.Print("Enter the file path: ")
var filePath string
fmt.Scanln(&filePath)
//slip3
package main
// import "fmt"
// func main() {
// var num, res, sum, originalNum int
// fmt.Println("Enter The Number:")
// fmt.Scanln(&num)
// originalNum = num
// if originalNum == sum {
// fmt.Println("Number Is Palindrome")
// } else {
// fmt.Println("Number Is Not Palindrome")
// }
// }
package main
import (
"fmt"
)
func main() {
var n int
fmt.Println("Enter the number of employees:")
fmt.Scanln(&n)
employees := make([]employee, n)
slip4
package main
import (
"fmt"
)
func main() {
// Prompt the user to enter the number
fmt.Print("Enter a number: ")
var num int
fmt.Scanln(&num)
package main
// import (
// "fmt"
// "sort"
// )
// func main(){
// num :=[]int{22,33,4,1,60,56,78,8}
// sort.Ints(num)
// }
slip 5
package main
import (
"fmt"
"os"
)
func main() {
// Create a file
file, err := os.Create("employees.txt")
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()
package main
import (
"fmt"
"os"
)
func main() {
var n int
fmt.Println("Enter the number of employees:")
fmt.Scanln(&n)
employees := make([]employee, n)
var minSalary float64
slip 6
A)Write a program in GO language to
accept two matrices and display its
multiplication
package main
import "fmt"
func main() {
var rows1, cols1, rows2, cols2 int
if cols1 != rows2 {
fmt.Println("Matrices cannot be multiplied. Number of columns of first
matrix must be equal to number of rows of second matrix.")
return
}
package main
import "fmt"
func main() {
source := []int{1, 2, 3, 4, 5}
destination := make([]int, len(source))
copyArray(source, destination)
slip7
package main
// import (
// "fmt"
// )
// func main() {
// s := student{
// Name: "Sahid Shaikh",
// Age: 20,
// Gender: "Male",
// }
// s.show()
// }
slip8
package main
// import (
// "fmt"
// )
// func main() {
// var n int
// fmt.Println("Enter the number of books:")
// fmt.Scan(&n)
// books := make([]book, n)
package main
import (
"fmt"
"math"
)
// Shape interface
type Shape interface {
Area() float64
Perimeter() float64
}
// Circle type
type Circle struct {
Radius float64
}
// Rectangle type
type Rectangle struct {
Length float64
Width float64
}
func main() {
// Create a circle with radius 5
circle := Circle{Radius: 5}
fmt.Println("Circle - Area:", circle.Area())
fmt.Println("Circle - Perimeter:", circle.Perimeter())
slip9
A) Write a program in GO language to
create an interface and display its
values with the help of type
assertion.
package main
import "fmt"
// Shape interface
type Shape interface {
Area() float64
}
// Circle type
type Circle struct {
Radius float64
}
// Rectangle type
type Rectangle struct {
Length float64
Width float64
}
func main() {
// Define a slice of shapes
shapes := []Shape{
Circle{Radius: 5},
Rectangle{Length: 4, Width: 3},
}
// Display areas of shapes using type assertion
for _, shape := range shapes {
switch s := shape.(type) {
case Circle:
fmt.Printf("Circle - Area: %.2f\n", s.Area())
case Rectangle:
fmt.Printf("Rectangle - Area: %.2f\n", s.Area())
}
}
}
// import "fmt"
// func main() {
// ch := make(chan int)
// go fibonacci(ch, 10)
slip 10
package main
// import "fmt"
// func main(){
// var num int
slip 12
// package main
// import "fmt"
// func main() {
// var a, b int
// a = 10
// b = 20
// swap(&a, &b)
slip 13
A) Write a program in GO language to print
sum of all even and odd numbers
separately between 1 to 100.
package main
// import "fmt"
// func main(){
// var evensum,oddsum,i int
// for i=0;i<=100;i++{
// if i%2==0 {
// evensum+=i
// }else {
// oddsum+=i
// }
// }
package main
import (
"testing"
)
go test -bench=.
slip14
package main
// import "fmt"
// func main() {
// slice := []int{1, 2, 3, 4, 5}
// fmt.Println("After Remove",slice)
// }
slip15
package main
// import (
// "fmt"
// "time"
// )
// func main() {
// for i := 0; i <= 10; i++ {
// fmt.Println(i)
// delay(250 * time.Millisecond)
// }
// }
slip16
// import "fmt"
// sum:=a+b
// sub:=a-b
// mul:=a*b
// div:=a/b
// return sum,sub,mul,div
// }
// func main(){
// sum,sub,mul,div:=multiple(50,25)
// fmt.Println("Sum IS :",sum)
// fmt.Println("Sub IS :",sub)
// fmt.Println("Mul IS :",mul)
// fmt.Println("Division IS :",div)
// }
B) Write a program in GO language to
read XML file into structure and
display structure
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
)
func main() {
// Open the XML file
file, err := os.Open("employees.xml")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer file.Close()
package main
// import "fmt"
// func main(){
// multiplication(12)
// }
// calculator.go
package calculator
// main.go
package main
import (
"fmt"
"calculator"
)
func main() {
var choice int
var a, b float64
fmt.Println("Choose operation:")
fmt.Println("1. Add")
fmt.Println("2. Subtract")
fmt.Println("3. Multiply")
fmt.Println("4. Divide")
switch choice {
case 1:
result = calculator.Add(a, b)
case 2:
result = calculator.Subtract(a, b)
case 3:
result = calculator.Multiply(a, b)
case 4:
result = calculator.Divide(a, b)
default:
fmt.Println("Invalid choice")
return
}
fmt.Println("Result:", result)
}
slip19
package main
// import "fmt"
// func main() {
// num1,num2:=50,20
// sum,sub:=multiple(num1,num2)
// fmt.Println("Sum Is : ",sum)
// fmt.Println("Sub Is :",sub)
// }
package main
import (
"fmt"
"os"
)
func main() {
// Open the file in read-only mode
file, err := os.Open("example.txt")
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
slip 20
A) Write a program in Go language to
add or append content at the end of a
text file.
package main
import (
"fmt"
"os"
)
func main() {
// Open the file in append mode, create it if it doesn't exist
file, err := os.OpenFile("example.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE,
0644)
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
// Write content to the file
content := "This is new content to be added."
_, err = file.WriteString(content + "\n")
if err != nil {
fmt.Println("Error:", err)
return
}
package main
import (
"fmt"
)
func main() {
// Create a channel of type int
ch := make(chan int)
fmt.Println("Channel closed.")
}