C Programming Homework Help – The Best of the Best in the UKThe C programming language is one of the most common languages and the most preferred by the majority of institutions when it comes to introducing learners to programming. Most of the high-level programming languages we have today are a lot...
Two-dimensional arrays
import java.util.Scanner;
public class Assignment {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
// We have 4 days, and 5 classes per day
// Fill the lecture rooms
String[][] Woodward106 = new String[4][5];
String[][] Cameron171 = new String[4][5];
// CSC110 is in mondays and wednesdays, at the first class of day
Woodward106[0][0] = "CSC1100";
Woodward106[0][1] = "CSC1213";
Woodward106[0][2] = "CSC2175";
Woodward106[0][3] = "ENGL2116";
Woodward106[0][4] = "CSC3155";
Woodward106[1][0] = "CSC2200";
Woodward106[1][1] = "ITCS3688";
Woodward106[1][2] = "CSC3146";
Woodward106[1][3] = "MATH1241";
Woodward106[1][4] = "CSC3181";
Woodward106[2][0] = "CSC1100";
Woodward106[2][1] = "CSC1213";
Woodward106[2][2] = "CSC2175";
Woodward106[2][3] = "ENGL2116";
Woodward106[2][4] = "CSC3155";
Woodward106[3][0] = "CSC1100";
Woodward106[3][1] = "CSC1213";
Woodward106[3][2] = "CSC2175";
Woodward106[3][3] = "ENGL2116";
Woodward106[3][4] = "CSC3155";
Woodward106[4][0] = "CSC2200";
Woodward106[4][1] = "CSC3688";
Woodward106[4][2] = "ITSC3146";
Woodward106[4][3] = "MATH1241";
Woodward106[4][4] = "CSC3181";
Cameron171[0][0] = "ITIS3130";
Cameron171[0][1] = "ITCS3134";
Cameron171[0][2] = "ITIS3200";
Cameron171[0][3] = "ITCS3153";
Cameron171[0][4] = "ITIS3216";
Cameron171[1][0] = "ITCS2600";
Cameron171[1][1] = "ITIS3135";
Cameron171[1][2] = "ITCS3160";
Cameron171[1][3] = "ITIS3320";
Cameron171[1][4] = "ITCS3166";
Cameron171[2][0] = "ITIS3130";
Cameron171[2][1] = "ITCS3134";
Cameron171[2][2] = "ITIS3200";
Cameron171[2][3] = "ITCS3153";
Cameron171[2][4] = "ITIS3216";
Cameron171[3][0] = "ITCS2600";
Cameron171[3][1] = "ITIS3135";
Cameron171[3][2] = "ITCS3160";
Cameron171[3][3] = "ITIS3320";
Cameron171[3][4] = "ITCS3166";
// Now, ask student for courses
int stop = 0;
int N = 5; // number of courses to be entered
while(stop == 0)
{
String courses[] = new String[N];
for(int i = 0; i< N; i++)
{
System.out.print("Enter course No. " + (i+1) + ": ");
courses[i] = sc.next();
}
// Now, check if the courses are valid
booleanvalid_schedule = true;
for(int i = 0; i< N; i++)
{
boolean valid = false;
// Iterate through days
for(int day = 0; day < 4; day++ )
{
// Iterate through classes
for(int cl = 0; cl < 5; cl++)
{
if(Woodward106[day][cl].toLowerCase().compareTo(courses[i].toLowerCase()) == 0 || Cameron171[day][cl].toLowerCase().compareTo(courses[i].toLowerCase()) == 0) // Course is valid
{
valid = true;
break;
}
if(valid)
break;
}
}
if(!valid) // course not valid
{
System.out.println("Course " + courses[i] + " is not offered in the lecture rooms.");
valid_schedule = false;
}
}
if(!valid_schedule)
{
System.out.print("Some of the courses you entered are not valid. Do you want to enter the courses again? (y/n): ");
String input = sc.next();
if(input == "n")
stop = 1;
}
// At this point, we know that the courses are valid. Now, let's check if there is conflict with hours
for(int i = 0; i< N; i++)
{
for(int j = 0; j < N; j++)
{
if(i != j)
{
String coursei = courses[i];
String coursej = courses[j];
// Check that both courses are not present at the same time
for(int day = 0; day < 4; day++ )
{
// Iterate through classes
for(int cl = 0; cl < 5; cl++)
{
if(Woodward106[day][cl].toLowerCase().compareTo(coursei.toLowerCase()) == 0 || Cameron171[day][cl].toLowerCase().compareTo(coursei.toLowerCase()) == 0) // Course is valid
{
if(Woodward106[day][cl].toLowerCase().compareTo(coursej.toLowerCase()) == 0 || Cameron171[day][cl].toLowerCase().compareTo(coursej.toLowerCase()) == 0) // Course is valid
{
if(coursei.toLowerCase().compareTo(coursej.toLowerCase()) != 0)
{
valid_schedule = false;
System.out.println("Courses " + coursei + " and " + coursej + " are time conflict.");
break;
}
}
}
}
}
}
}
}
if(!valid_schedule)
{
System.out.print("Some of the courses you entered are not valid. Do you want to enter the courses again? (y/n): ");
String input = sc.next();
if(input == "n")
stop = 1;
}
else
{
// The schedule is valid
System.out.println("Congratulations! Your schedule has been settled!");
stop = 1;
}
}
}
}
Understanding arrays and strings
#include
#include
#include
#include
using namespace std;
//The function reads and stores data in the parallel array and 2D array from a text file(aidata.txt).
void loadData(ifstream&infile, string occupations[], int nums[][2], int& rows);
//This function finds and updates the highest percentage of the susceptibility of automation and the corresponding occupation.
void findHigh(string occupations[], int nums[][2], int rows, string& occupation, double&highPercent);
//This function finds and updates the lowest percentage of the susceptibility of automation and the corresponding occupation.
void findLow(string occupations[], int nums[][2], int rows, string& occupation, double&lowPercent);
int main() {
// open the file
ifstream input("aidata.txt");
// initialize arrays with a maximum size of 100
string occups[100];
int nums[100][2]; // this is a two dimensional array
int size;
// output of functions variables
string highOcu, lowOcu;
double highPerc, lowPerc;
// checking file for errors
if (!input.good()) {
exit(-1);
}
cout<< "Highest/Lowest Occupations Susceptible to Automation:" <> occupations[rows]) {
infile>>nums[rows][0] >>nums[rows][1];
rows++;
}
}
void findHigh(string occupations[], int nums[][2], int rows, string& occupation, double&highPercent)
{
// set the high with the first value in the arrays
highPercent = nums[0][1] / (double)nums[0][0];
occupation = occupations[0];
for (int i = 1; i< rows; i++)
{
// if it is greater thelan the current max set it to the max
if (nums[i][1] / (double)nums[i][0] >highPercent) {
highPercent = nums[i][1] / (double)nums[i][0];
occupation = occupations[i];
}
}
}
void findLow(string occupations[], int nums[][2], int rows, string& occupation, double&lowPercent)
{
// set the low with the first value in the arrays
lowPercent = nums[0][1] / (double)nums[0][0];
occupation = occupations[0];
for (int i = 1; i< rows; i++)
{
// if it is less than the current max set it to the max
if (nums[i][1] / (double)nums[i][0]