0

Assignment 2 Cs508 – Modern programming languages Semester Spring 2021

cs508 assignment 2 solution 2021

CODE:

START
	STRING = INPUT
	OUTPUT = "Please Enter a String: " STRING
	A1 = ('a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U') . V
        B2 = ('b' | 'c' | 'd' | 'f' | 'g' | 'j' | 'k' | 'l' | 'm' | 'n' | 'p' | 'q' | 'r' | 's' | 't' | 'v' | 'w' | 'x' | 'y' | 'z' | 'B' | 'C' | 'D' | 'F' | 'G' | 'H' | 'J' | 'K' | 'L' | 'M' | 'N' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'V' | 'W' | 'X' | 'Y' | 'Z') . C
	
	STR1 = ''
	STR2 = ''

	CNTR1 = 0
	CNTR2 = 0

ALABEL STRING A1 = :F(BLABEL)
	STR1 = STR1 '' V
	CNTR1 = CNTR1 + 1 :S(ALABEL)

BLABEL STRING B2 = :F(RESULT)
	STR2 = STR2 '' C
	CNTR2 = CNTR2 + 1 :S(ALABEL)

RESULT OUTPUT = 'FOUND' CNTR1 'VOWELS' STR1
	OUTPUT = 'FOUND' CNTR2 'Cons' STR2
END

DEMO:

TAGS:

virtual university,cs508 assignment solution,assignment solution,assignment solution spring 2021,cs508 assignment 1 solution 2021,cs508 solution,cs408 assignment 1 solution 2021,vu assignment,cs508 assignment no 3,cs302 assignment 2 solution 2021,cs607 assignment 2 solution 2021,cs508 assignment 3 solution 2020,cs508 assignment no 3 solution fall 2020,cs508 assignment no 3 solution,cs508 assignment 1,cs411 assignment 2 solution 2021,cs508 assignment no 1 solution spring 2021,assignment

0

CS201 Assignment 2 Solution Spring 2021

Problem Statement:

Write a program that stores matrix 2 * 2 and find transpose, adjoint, and determination using functions.

CODE:

#include <iostream>

#include <conio.h>

using namespace std;
int ShowMatrix() {
  int row = 2, column = 2;
  int matrix[2][2] = {
    {
      8,
      -4
    },
    {
      -6,
      2
    }
  };
  cout << "The matrix is:" << endl;
  for (int i = 0; i < row; ++i) {
    for (int j = 0; j < column; ++j)
      cout << matrix[i][j] << " ";
    cout << endl;
  }
}
int showTranspose() {
  int transpose[2][2], row = 2, column = 2, i, j;
  int matrix[2][2] = {
    {
      8,
      -4
    },
    {
      -6,
      2
    }
  };
  cout << endl;
  for (i = 0; i < row; ++i)
    for (j = 0; j < column; ++j) {
      transpose[j][i] = matrix[i][j];
    }
  cout << "The transpose of the matrix is:" << endl;
  for (i = 0; i < column; ++i) {
    for (j = 0; j < row; ++j)
      cout << transpose[i][j] << " ";
    cout << endl;
  }
}
int calculateDeterminant() {
  int determMatrix[2][2], determinant;
  int matrix[2][2] = {
    {
      8,
      -4
    },
    {
      -6,
      2
    }
  };
  determinant = ((matrix[0][0] * matrix[1][1]) -
    (matrix[0][1] * matrix[1][0]));
  cout << "\nThe Determinant of 2 * 2 Matrix = " << determinant;
}
int showAdjoint() {
  int ch, A2[2][2] = {
    {
      8,
      -4
    },
    {
      -6,
      2
    }
  }, AD2[2][2], C2[2][2];
  //Calculating cofactors of a matrix of order 2x2
  C2[0][0] = A2[1][1];
  C2[0][1] = -A2[1][0];
  C2[1][0] = -A2[0][1];
  C2[1][1] = A2[0][0];
  //calculating adjoint of the matrix of order 2x2
  AD2[0][0] = C2[0][0];
  AD2[0][1] = C2[1][0];
  AD2[1][0] = C2[0][1];
  AD2[1][1] = C2[1][1];
  cout << "\n\nAdjoint of A is :- \n\n";
  cout << "|\t" << AD2[0][0] << "\t" << AD2[0][1] << "\t|\n|\t" << AD2[1][0] << "\t" << AD2[1][1] << "\t|\n";
}
int main() {
  int choice = 0;
  cout << "Enter your choice " << endl;
  cout << "Press 1 to display the matrix and its transpose" << endl;
  cout << "Press 2 to find adjoint and determinant of the matrix" << endl;
  cout << "Press any other key to exit.";
  cin >> choice;
  if (choice == 1) {
    ShowMatrix();
    showTranspose();
  } else if (choice == 2) {
    showAdjoint();
    calculateDeterminant();
  } else
    system("pause");
}

DEMO:

0

Data Structures (CS301) Assignment # 02 Semester Spring 2021

Data Structures (CS301) Assignment # 02

Problem Statement:

Due to the Coronavirus pandemic Government has asked all the major grocery stores to serve the customers as soon as possible so that the gathering of the people may be avoided. In this regard all the grocery stores have decided that there will be two queues for the customers at each grocery store. One queue is the express queue and second is the normal queue. Express queue will have the customers which have bought 5 or less than 5  grocery items. Similarly normal queue will have the customers with grocery items greater than 5. These queues will help the customer to choose the  line according to their grocery shopping requirements and they will have to wait in their queue accordingly. The idea is to develop a C++ program that could serve the purpose of FIFO (first come first served)for both express and normal service queues so that each customer may select queue according to his/her shopping requirements. The program must have the features to:
·         Record the information of the customer (name, shopping information etc.) and identify the type of customer so that he/she may select express queue or normal queue)
·         Simulate both express and normal queues i.e., count the number of customers and the serving time of each customer in each queue.
The program must have the following functional features:
1.        Record information of each customer that would be the customer name, customer id, number of grocery items purchased.
2.        Send each customer to either express queue or normal queue based on the number  of grocery items customer has purchased.
3.        Keep the count of customers in each queue. Whenever a customer enters or exits a queue display the total number of customers in that queue
4.        Print the information of the customers of both the queues.
Furthermore: You need to consider following necessary steps while developing the solution.
·         Use linked list to make queue of customers. Here CustomerNode class will be used in place of Node class.
·         Create a single CustomerQueue class to handle both express and normal queues customers. Use addCustomer(enqueue), removeCustomer(dequeue) and methods for smooth operations of queue.
·         Collect all information of customers like
o   Customer Name, Customer ID, Number of grocery items purchased,
·         After getting required information of customer, check the number of grocery items customer has purchased and then put him in the respective queue.
Whenever a customer enters into a queue print the message “Customer entered in express/normal queue” and also print the total number of customers in that queue. Use removeCustomer() method to remove customer one by one and display the information of that customer along with the remaining customers count of each queue.

CODE :

#include<iostream>
#include<string>

using namespace std;

class CustomerNode{
	public:
		int cid = 0;
		string cname = "";
		int pitem = 0;
		CustomerNode *next;
};


class CustomerQueue{
	public:
		CustomerNode *front, *rear;
		CustomerQueue(){
			front = rear = NULL;
		}
		
		void addCustomeer(int,string,int);
		void removeCustomer(char,int);
		void display(CustomerNode*,string,int);
};

void CustomerQueue::addCustomeer(int id,string name,int item){
	CustomerNode *newNode = new CustomerNode;
	
	newNode -> cid = id;
	newNode -> cname = name;
	newNode -> pitem = item;
	newNode-> next = NULL;
	
	if(front == NULL){
		front = rear = newNode;
		rear -> next = NULL;
	}else{
		while(rear->next != NULL){
			rear = rear ->next;
		}
		rear ->next = newNode;
		rear = newNode;
	}
}


void CustomerQueue::removeCustomer(char q,int count){
	CustomerNode *temp = front;
	string queue;
	if(front == NULL){
		rear = NULL;
		if(q == 'n'){
			queue = "Normal";
		}else{
			queue = "Express";
		}
		cout<<"----"<<queue<<" Queue Customer Information----"<<endl;
		cout<<queue<<"Queue is empty"<<endl;
	}else{
		
		if(q == 'n'){
			queue = "Normal";
		}else{
			queue = "Express";
		}
		cout<<"----"<<queue<<" Queue Customer Information----"<<endl;
		display(temp,queue,count);
		delete(temp);
	}
	
}


void CustomerQueue::display(CustomerNode* temp,string queue,int count){
	temp = front;
	while(temp!=NULL){
		cout<<"Customer ID = "<<temp->cid<<endl;
		cout<<"Customer Name = "<<temp->pitem<<endl;
		cout<<"Total Customer in "<<queue<<" Queue = "<<--count<<endl;
		temp=temp->next;
	}
	
}

int main(){
	CustomerQueue express,normal;
	int id = 0,item = 0,exp_count = 0,nor_count = 0;
	string name;
	bool check = true;
	char choice,exp = 'e',nor='n';
	
	while(check){
		cout<<"---Enter Customer Information---"<<endl;
		cout<<"Custometr  ID = ";
		cin>>id;
		cout<<"Custometr  Name = ";
		cin>>name;
		cout<<"Item Purchesed = ";
		cin>>item;
		if(item <= 5){
			cout<<"---------- Customer Entered in Express Queue ----------"<<endl;
			express.addCustomeer(id,name,item);
			exp_count++;
			cout<<"Total Number of Customer in Express Queue = "<<exp_count<<endl;
			
		}else{
			cout<<"------ Customer Entered in Normal Queue ---"<<endl;
			express.addCustomeer(id,name,item);
			nor_count++;
			cout<<"Total Number of Customer in Normal Queue = "<<nor_count<<endl;
		}
		
		
		cout<<"\nDo you want to enter another Customer Y for yes or N for no : ";
		cin>>choice;
		if(choice == 'n' || choice == 'N'){
			express.removeCustomer(exp,exp_count);
			normal.removeCustomer(nor,nor_count);
			check = false;
		}
	}
	
	return 0;
}
0

implementation of encryption using python

implementation of encryption using python

implementation of encryption using python – You realized that your encryption method is too naive, now you want to change your and make it more sophisticated. You came up an idea that to move each plaintext character k steps forward to become another character. For example, if k = 4, 4 steps forward of the character ‘a’ is ‘e’, and 4 steps forward of the character ‘b’ is ‘f’.

cipher4

In [ ]:

# Hints
# you can convert "a" to number 1 by thinking a 36-decimal system 
# (we borrow the idea of hexdecimal system). i.e. a=10, b=11, ... z=35

int("a", 36)

Out[ ]:

10

In [ ]:

# test for "z"
int("z", 36)

Out[ ]:

35

Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as ‘a’ or ‘@’ or an action of some sort.

Given the following ASCII table:

DecChrDecChrDecChr
97a106j115s
98b107k116t
99c108l117u
100d109m118v
101e110n119w
102f111o120x
103g112p121y
104h113q122z
105i114r

You can find out more about ASCII code here: ASCIIIn [ ]:

chr(97)

Out[ ]:

'a'

In [ ]:

# you can do a conversion from number to character by the following sample code
# In your 36-decimal system, 10 represent and "a", and you know that 97 represent "a" in ASCII system, 
# so you can simply add 87 (97-10) to get your character in your 36-decimal system.

value = int("a", 36)  ## it give your value of 10
value = value - 10    ## it is better to shift your character in a range of 1-25, instead of 10-35
chr(value+97)   ## it should give you back character "a", We only use the ASCII table in the range of 97 to 122.

Out[ ]:

'a'

Implement the encryption algorithm and named your function as encrpt2. Take one argument as the input and one argument contains the value k. You only require to handle lowercase character. You NO need to handle special character such as space bar.In [30]:

# implementation of encryption using python

# k = 4 is for testing, your program should work for any value of n

k = 4

def encrypt2(input, k):
    output = ""    
# write your program below:
    for c in input:
        value = int(c, 36)
        value = value - 10
        if value+k > 25:
            value = value-26
        value = value+97+k
        c = chr(value)
        output += c
    return output

In [31]:

# test your function
encrypt2("abcdefghijklmnopqrstuvwxyz", 1)

Out[31]:

'bcdefghijklmnopqrstuvwxyza'

In [32]:

# test your function
encrypt2("abcdefghijklmnopqrstuvwxyz", 4)

Out[32]:

'efghijklmnopqrstuvwxyzabcd'

If you have another efficient way to do this, please share in the comment section.

If you have also done the same(implementation of encryption using python) in python or any other language works. Share it in the comments section to help others

keep visiting : shaadcoding

1

simple substitution cipher implementation using Python

substitution cipher implementation using Python

substitution cipher implementation using Python – You want to develop a secret communication method with your friend. One day, you read a book about a simple substitution cipher and you want to implement it by using Python.

The logic of substitution cipher implementation using Python is easy. Your friend and you came up with the following naive substitution algorithm.

cipher3

That is, you swap characters “a” with “c”, “d” with “q”, “i” with “m”, and “t” with “y”. Other characters leave unchanged.

Based on your algorithm, a plaintext “raymond” will be encrypted as “rctionq”.

Implement the encryption algorithm and named your function as encrpt. Take one argument as the input and one argument contains the key pairs. You only require to handle lowercase character.

A two-dimension array is used to represent the key-value pairs.

keys = [["a", "c"], ["c", "a"], ["d", "q"], ["i", "m"], ["m", "i"], ["q", "d"], ["t", "y"], ["y", "t"]]

You can access the first key pair by keys[0]In [ ]:

keys = [["a", "c"], ["c", "a"], ["d", "q"], ["i", "m"], ["m", "i"], ["q", "d"], ["t", "y"], ["y", "t"]]

keys[0]

Out[ ]:

['a', 'c']

The first key can be obtained by keys[0][0]In [ ]:

keys[0][0]

Out[ ]:

'a'

The first value of key “a” can be obtained by keys[0][1]In [ ]:

keys[0][1]

Out[ ]:

'c'

The last pair of key can be obtained by the following example code:In [ ]:

last = len(keys)   # last = 8
print(keys[(last-1)])     # the first index is 0, the last index is 7. and this will give you a list of ["y", "t"]

# assign the last keypair to a variable named temp
temp = keys[(last-1)]
print(temp)     # it will give you the same ouput as above

print(temp[0])  # "y"
print(temp[1])  # "t"
['y', 't']
['y', 't']
y
t

You can test your function by checking the following input-output pairs.
Input: “raymond”
Ouput: “rctionq”


Input: “peter is a good guy”
Output: “peyer ms c gooq gut”

if you really can’t use a flexible way to implement the code, you can forget about the keys variable and use if-else statements to complete itIn [11]:

# implementation


keys = [["a", "c"], ["c", "a"], ["d", "q"], ["i", "m"], ["m", "i"], ["q", "d"], ["t", "y"], ["y", "t"]]

input = "raymond"

def encrypt(input, keys):
    output = ""

    # Write your code below:
    for c in input:
        for k in keys:
            if c == k[0]:
                c = k[1]
                break
        output += c
    return output
                
            

In [12]:

# Test your function
encrypt("raymond", keys)

Out[12]:

'rctionq'

If you have another efficient method, please share the comment section.

If you have also used python or any other language to do your work. Share it in the comments section to help others

keep visiting : shaadcoding

0

hexadecimal to decimal in python(Easy Solution)

hexadecimal to decimal in python

hexadecimal string to a decimal value in python – Write a function that converts the hexadecimal string to a decimal value. You can NOT use any Python library/module to help you do it. Your function name should be named hex and take one argument as the input.

In mathematics and calculations, the hexadecimal number system (also 16 or hexadecimal) is a positional number system that uses the base 16 to represent numbers. Unlike the usual way of using 10 symbols to represent numbers, hexadecimal uses 16 different symbols. In most cases, the symbols “0” – “9” represent values ​​from 0 to 9 and “A” – “F” (or “A” – “f”) represent values ​​from 10 to 15.

The decimal numeral system (also called the base-ten positional numeral system, and occasionally called denary/ˈdiːnəri/[1] or decanary) is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral system.[2] The way of denoting numbers in the decimal system is often referred to as decimal notation.[3]

For example, if the input is “F23A”, the decminal value is 62010 and the procedure in the conversion is at below:

QUESTION 2

Hints: you can use int('A', 16) to convert a hex string value to dec integer. Also, you can use funtion len(input) to find out the length of the string. You can extract a particular character in a string by specifying an index.

# Below codes are hints
# exmaple

a = "F23A"
print(len(a))
print(a[3])
print(int(a[3],16))
4
A
10

In [8]:

# Implementation

input = "F23A"

# Start the code below
def hex(s):
    l = len(s) - 1
    d = 0
    for c in s:
        res = int(c,16)*(16**l)
        d += res
        l -= 1
    return d
        
  

In [9]:

# test your code here
input = "F23A"
hex(input)

Out[9]:

62010

If you have another efficient method, please share the comment section.

If you also use Python or any other language to do your work(hexadecimal string to a decimal value in python). Share it in the comment section to help others

keep visiting : shaadcoding

0

List of Even numbers below a certain value in python.

List of Even numbers in python

Topic – List of Even numbers below a certain value in python

EXPLANATION:

For example, if k = 16, your function should return a list of [2,4,6,8,10,12,14]

Name your function as even_list() that takes one argument named k.In [ ]:

# hints:
# you can create an empty list and append items on it by the following code:

a = []
a.append(4)
a.append(6)
print(a)
[4, 6]

In [4]:

let’s start – List of Even numbers below a certain value in python

List of Even numbers in python – CODE

# Implementation

# write your code below
def even_list(k):
    even = []
    for i in range(1,k):
        if i % 2 == 0:
            even.append(i)
    return even

In [5]:

# test your function here
even_list(16)

Out[5]:

[2, 4, 6, 8, 10, 12, 14] 

If you have another efficient method, please share the comment section.

If you also use Python or any other language to complete the job. Share it in the comment section to help others

keep visiting : shaadcoding

1

copy content of one file to another using Python

copy content of one file to another using Python

other statements for same problem:

  1. Python Program to Copy the Contents of One File into Another
  2. The program copies the contents of one file and writes it into another.
  3. Python – Copy contents of one file to another file
  4. Copying from one text file to another using Python

copy content of one file to another using python – “Today’s Topic”

How to copy from one text file to another using python?

Suppose we have a file and we want to save the content of this file in another for backup so, how we can do this using python?

Python is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use. Python’s license is administered by the Python Software Foundation.

python allows us to do this in quick and efficient manner , So let get started…

Make sure you have downloaded and installed python if you haven’t download python yet then follow the tutorial to download python :

Downloading and setting up python

we will have a file, in our case file name “file1.txt” and we will copy the content of “file1.txt” to another file named “file2.txt”. Copy the line below and create a file “file1.txt” and paste these line it, you can also create your own testing file with any other content in it, you can also give a name to this file according to you but please make sure to also change the file name in code too accordingly, Still confusion? drop your question in the comment section, i will try my best to solve your query as soon as possible

file1.txt :

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5

The Simples way of Copying content of “file1.txt” to “file2.txt” is as follows :

PYTHON CODE:

with open("file1.txt") as file1:
with open("file2.txt", "w") as file2:
for line in file1:
file2.write(line)

After running the above code “file2.txt” will be created in same working directory with all content of “file1.txt”

file2.txt:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5

If you have another effective way to accomplish this task. About using Python to copy content from one file to another, then share it in the comment section.

If you have also done the same in python or any other language works . Share it in the comments section to help others

DEMO:

keep visiting : shaadcoding