MIS Programming Assignment 4
.docx
keyboard_arrow_up
School
University Of Arizona *
*We aren’t endorsed by this school
Course
301
Subject
Computer Science
Date
Apr 3, 2024
Type
docx
Pages
4
Uploaded by CoachDiscovery2101
MIS Programming Assignment 4
By Tanishka Bansal
Code:
# Tanishka Bansal Programming Assignment 4
def main():
# print basic Info about the program using info function
info()
# Read and split data file and store in square_data
# dimension of the first square is the first value in square_data
square_data = open("magicData.txt")
all_data = square_data.read().split()
index = 0
number = 1
while index < len(all_data) and all_data[index] != '-1':
size = int(all_data[index])
print("The size of the square is:", size)
print("*" * 5, "Square", number, "*" * 5)
square = [[0] * size for _ in range(size)]
# prints out matrix using nested loops
index += 1
for i in range(size):
for j in range(size):
square[i][j] = int(all_data[index])
print(square[i][j], end=" ")
index += 1
print()
# use sum_rows function to compute the sum of each of the rows
row_sums = sum_rows(square)
# use sum_cols function to compute the sum of each of the columns
col_sums = sum_cols(square)
# use sum_main_diag to compute the sum of the main diagonal
main_diag_sum = sum_main_diag(square)
# use sum_off_diag to compute the sum of the off diagonal
off_diag_sum = sum_off_diag(square)
# determine if the square matrix is perfect and print the result
is_perfect = is_magic_square(row_sums, col_sums, main_diag_sum, off_diag_sum)
print("Is it a magic square?", is_perfect)
number += 1
square_data.close()
def sum_rows(matrix):
return [sum(row) for row in matrix]
def sum_cols(matrix):
return [sum(col) for col in zip(*matrix)]
def sum_main_diag(matrix):
return sum(matrix[i][i] for i in range(len(matrix)))
def sum_off_diag(matrix):
return sum(matrix[i][len(matrix) - i - 1] for i in range(len(matrix)))
def is_magic_square(row_sums, col_sums, main_diag_sum, off_diag_sum):
# Check if all row sums, column sums, and diagonals have the same value
return all(val == row_sums[0] for val in row_sums) \
and all(val == col_sums[0] for val in col_sums) \
and main_diag_sum == off_diag_sum == row_sums[0]
def info():
print("This program reads a series of square matrices from a file and determines if each matrix is a magic square.")
main()
Screenshot of code:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Computer Science
C++
Convert following program to use a loop and step through input the data for each division , also recive data from an input file that contains 4 row
(for each division) and 4 column for each quarter sales
//Name://Date://Problem statemnt: Corporate Sales Data Page 659 Gaddis#include#include#includeusing namespace std;// Declaration of the Division structure.struct Division{ string name; // Division name double quarter1; // First quarter sales double quarter2; // Second quarter sales double quarter3; // Third quarter sales double quarter4; // Fourth quarter sales double annualSales; // Annual sales double averageQtrSales; // Average quarterly sales};int main(){ //================= Create structure variables for each division. =================== Division east, west, north, south; //============= Store the names of the divisions. =================================== east.name = "East"; west.name =…
arrow_forward
FILE HANDLING
please attach sourcecode/ c language program
arrow_forward
Programming fundamentals
String data type is not allowed you can make use of CString instead (char arrays with null termination).
Q1. Create an Input File with the following information regarding to inventory:
Item_Id Price Quantity Availability
Add atleast 10 records in input file.
Where item_id will be of type int , price will be of type double , quantity will be of type int and Availability will be of type char representing the status y for yes the product is available and n for not available.
arrow_forward
C++ Language
arrow_forward
It is a type used to represent a heterogeneous collection of data.
array
O function
struct
pointer
Check It!
Structure is a user-defined data type in C which allows you to
combine different data types to store a particular type of record.
O True
False
Check It!
arrow_forward
Programming language : C++
Note : you have to use file handling
Question :
you are asked to make a program in c ++ in which you have to Write a function to search for student details ( name and class ) from a file using the enrollment of student.
arrow_forward
simple detailed code please
C program that Read a file The file contains data about the students : first name, last, name, email, and ID. and Store the content of the file in an array of students. Student is a C structure with the following members: • First name Last name email ID
arrow_forward
instruction: C++ language
arrow_forward
Plz do it c programming in a basic way and plz explen the coods as a comment line
1b
arrow_forward
Describe different ways to manipulate data using a struct.
arrow_forward
Object Oriented Programming
C++ Language
please use comment
arrow_forward
- PROJECT REQUIREMENTS
Choose a programming project application to be
developed, then design and implement the
programming elements according to your creativity
using C++ language. The application must demonstrate
the integration of file I/O, records(struct), array and
functions.
You may follow the general framework for the
implementation phase as highlighted below:
Read data from file.
Store data into a struct array.
Process the data using functions. You may pass
variables, one dimensional array, two
dimensional array, struct variable or struct array
to functions, where appropriate.
Display the output to the screen, where
appropriate.
Write the output file, where appropriate.
O
O
O
O
O
arrow_forward
C++A new video store in your neighborhood is about to open. However, it does not have a program to keep track of its videos and customers. The store managers want someone to write a program for their system so that the video store can operate.
The program will require you to design 2 ADTs as described below:
[1] VIDEO ADT
Data
Operations
Video_ID (preferably int, auto-generated)
Movie Title
Genre
Production
Number of Copies
Movie Image Filename
[1] Insert a new video
[2] Rent a video; that is, check out a video
[3] Return a video, or check in, a video
[4] Show the details of a particular video
[5] Display all videos in the store
[6] Check whether a particular video is in the store
[2] CUSTOMER PARENT ADT
Data
Operations
Customer_ID (preferably int, auto-generated)
Name
Address
[1] Add Customer
[2] Show the customer details
[3] Print list of all customers
[3] CUSTOMER-RENT CHILD ADT
Customer_ID (
Video_ID (of all rented videos of a…
arrow_forward
This Program should be done using C language
Implement the Customer component following the requirements below using C Language...
Requirements-
Represent the Customers in your code using a 3D character array
The maximum number of customers that can be saved is 128.
Create a function list_customer which lists all customer data resembling the example run below.
Create a function add_customer which prompts the user to input new customer information. Your code should check to make sure the customer does not already exist before adding it to the 3D array. Also check that the customer can be added based on the maximum number of customers in the system.
Create a function get_customer which searches the customer data given an customer ID. If the customer exists, return the index within the data that the customer was found.
Create a function find_customer which accepts a string containing the name of an customer to search for. It should return the index of the customer in the database.
Each…
arrow_forward
c++ programming
need code for the sample run/output on the attached images
there are no restrictions with coding as long as it is under c++
you may use array and OOP and other structures if needed but make the code as simple and basic as it can get whenever possible
also please insert pseudocodes for better understanding
Thank you!
arrow_forward
File Handling with Array:
C++ Language:
Write a c++ program to read the data from the file into array and do calculation.
Note: Take a general word problem and write syntax which will use in all problems related to file handling with array.
arrow_forward
Allowed language: C language The output should be the same with example and please code correctly. Pls do not copy from other questions
arrow_forward
programming language : C
...
ex1_main.cpp
#include
#include
#include "lab2_ex1.h"
#include "lab2_ex1.cpp"
#define BUFFER 21
#define OUTPUT_FILE "output.txt"
int main(void)
{
char input[BUFFER];
printf("input: ");
fgets(input, BUFFER, stdin);
box_shift( input, OUTPUT_FILE);
return 0;
}
...
lab2_ex1.cpp
/*
EDIT THIS FILE TO SOLVE THE LABORATORY EXERCISES
*/
#include
#include
#include
#include
#include
using namespace std;
void box_shift(char *input, const char *filename)
{
// Open a file for writing
FILE *fp;
fp = fopen(filename, "w");
//ofstream writeFile;
//writeFile.open(filename);
string arr = "";
for (int i = 0; i < sizeof(input); i++) {
arr = arr + input[i];
}
int length;
int k, i = 0, j;
//cout << "Length (11 for [de la salle])? " << endl;
//cin >> length;
//arr = (char*) malloc (length * sizeof(char));
//cout <<…
arrow_forward
Plz do it c programming in a basic way and plz explen the coods as a comment line
2b
arrow_forward
Fix any syntax errors
#Lab 8 Dictionary and File I/O; source start file
import pickle
#Task #1: Define and Review Mainline Logic
def main():
print('Hello from main(); Lab 8 start file!!!')
#Task #2: Call Data Review Function
#view_winners_function()
#Task #3: Call Dictionary Function
#create_dictionary_function()
#Task #4: Call Serialization Function
#create_dictionary_serialization_function()
#Task #5: Call Application Function
user_application_function()
def user_application_function():
print('World Series Winner Application!!!\n')
input_year = int(input('What year do you want: '))
input_WS_data = open('ws_k_v_dictionary_pairs.dat')
world_series_dictionary_new = pickle.load(input_WS_data)
input_WS_data.close()
print(world_series_dictionary_new.get(input_year))
def create_dictionary_serialization_function():
#input
input_game_winners = open('WorldSeriesWinners.txt', 'r')
world_series_dictionary = {}
key_year = 1903
#Process
for line in input_game_winners:…
arrow_forward
Computer Science
The language used here is C++
Develop a C program that processes a file called
"grades.txt" containing a list of student grades and
outputs the minimum, maximum, and average
grade contained within that file. Your program
should make use of the following function
prototype:
void grades(FILE *inp, int *p_min, int *p_max, float
*p_ave);
Sample Output: Input File: 2 3 9 10 15 17 25 30 40
45 78 81 90
Output: Min: 2, Max: 90, Ave: 34.23
arrow_forward
q5)
If you are developing an application in which data is dynamic and will be defined at the time of execution of the program, then as a developer if you have the choice to select the correct structure for storing data from the following, what will be the correct choice?
a.
Linked list
b.
Depends on the Programming language.
c.
Arrays
d.
None
arrow_forward
C programming language
Topic
: Input/Output
Program
: Product list (product.c)
Definition : The program reads a series of items form a file and displays the data in columns. The
program obtains the file name from the command line. Each line of the file will have the following
form: item, mm-dd-yyyy, price
For example, suppose that the file contains the following lines:
123, 12.00, 12/25/2006
124, 18.30, 1/10/2020
Expected output:
Item
Unit
Purchase
Price
Date
123
$ 12.00
12/25/2006
124
$ 18.30
1/10/2020
arrow_forward
c program
add a report to count the total number of beaches in the file and how many are open, and how many are closed.
//include the required header file.
#include "stdio.h"
//Define the main function.
int main(void)
{
//Declare the variable.
int b_num, num_samples, num_orgs_per_100;
char c = 'a';
//Create a file pointer.
FILE *in_file;
//Open the file in read mode.
in_file = fopen("inp.txt", "r");
//Check if the file exists.
if (in_file == NULL)
printf("Error opening the file.\n");
//Read the data from the file.
else
{
//Get the beach number and number of
//samples from the file.
fscanf(in_file, "%d", &b_num);
fscanf(in_file, "%d", &num_samples);
//Check for end of file and beach
//number value and dispaly the samples.
while(!feof(in_file))
{
printf("\nb_num = %d, num_samples = %d",
b_num,num_samples);
for(int i =0;i<…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Related Questions
- Computer Science C++ Convert following program to use a loop and step through input the data for each division , also recive data from an input file that contains 4 row (for each division) and 4 column for each quarter sales //Name://Date://Problem statemnt: Corporate Sales Data Page 659 Gaddis#include#include#includeusing namespace std;// Declaration of the Division structure.struct Division{ string name; // Division name double quarter1; // First quarter sales double quarter2; // Second quarter sales double quarter3; // Third quarter sales double quarter4; // Fourth quarter sales double annualSales; // Annual sales double averageQtrSales; // Average quarterly sales};int main(){ //================= Create structure variables for each division. =================== Division east, west, north, south; //============= Store the names of the divisions. =================================== east.name = "East"; west.name =…arrow_forwardFILE HANDLING please attach sourcecode/ c language programarrow_forwardProgramming fundamentals String data type is not allowed you can make use of CString instead (char arrays with null termination). Q1. Create an Input File with the following information regarding to inventory: Item_Id Price Quantity Availability Add atleast 10 records in input file. Where item_id will be of type int , price will be of type double , quantity will be of type int and Availability will be of type char representing the status y for yes the product is available and n for not available.arrow_forward
- C++ Languagearrow_forwardIt is a type used to represent a heterogeneous collection of data. array O function struct pointer Check It! Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. O True False Check It!arrow_forwardProgramming language : C++ Note : you have to use file handling Question : you are asked to make a program in c ++ in which you have to Write a function to search for student details ( name and class ) from a file using the enrollment of student.arrow_forward
- simple detailed code please C program that Read a file The file contains data about the students : first name, last, name, email, and ID. and Store the content of the file in an array of students. Student is a C structure with the following members: • First name Last name email IDarrow_forwardinstruction: C++ languagearrow_forwardPlz do it c programming in a basic way and plz explen the coods as a comment line 1barrow_forward
- Describe different ways to manipulate data using a struct.arrow_forwardObject Oriented Programming C++ Language please use commentarrow_forward- PROJECT REQUIREMENTS Choose a programming project application to be developed, then design and implement the programming elements according to your creativity using C++ language. The application must demonstrate the integration of file I/O, records(struct), array and functions. You may follow the general framework for the implementation phase as highlighted below: Read data from file. Store data into a struct array. Process the data using functions. You may pass variables, one dimensional array, two dimensional array, struct variable or struct array to functions, where appropriate. Display the output to the screen, where appropriate. Write the output file, where appropriate. O O O O Oarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT