Answer:
C++ code is given below
Explanation:
#include <iostream>
#include <cctype>
#include <string.h>
#include <cstring>
#include <sstream>
using namespace std;
struct Car {
public:
char reportingMark[5];
int carNumber;
string kind;
bool loaded;
string destination;
};
void input(Car *);
void output(Car *);
int main() {
Car *T = new Car;
input(T);
output(T);
delete T;
return 0;
}
void input(Car *T)
{
string str, s;
cout << " Enter the reporting mark as a 5 or less character uppercase string: ";
cin >> str;
for (int i = 0; i < str.length(); i++)
T->reportingMark[i] = toupper(str[i]);
cout << " Enter the car number: ";
cin >> T->carNumber;
cout << " Enter the kind: ";
cin >> T->kind;
cout << " Enter the loaded status as true or false: ";
cin >> s;
istringstream(s) >> boolalpha >> T->loaded;
if (T->loaded == true) {
cout << " Enter the destination: ";
cin.ignore();
getline(cin, T->destination);
}
else
T->destination = "NONE";
}
void output(Car *T)
{
cout << " Reporting Mark: " << T->reportingMark;
cout << " Car Number: " << T->carNumber;
cout << " Kind: " << T->kind;
cout << " Loaded Status: " << boolalpha << T->loaded;
cout << " Destination: " << T->destination << " ";
}
Answer:
oid changeCase (char char_array[], int array_size ) {
__asm{
mov eax, char_array;
mov edi, 0;
readArray:
cmp edi, array_size;
jge exit;
mov ebx, edi;
shl ebx, 2;
mov cl, [eax + ebx];
check:
//working on it
cmp cl, 0x41;
jl next_indx;
cmp cl, 0x7A;
jg next_indx;
cmp cl, 'a';
jl convert_down;
jge convert_up;
convert_down:
or cl, 0x20; //make it lowercase
jmp write;
convert_up:
and cl, 0x20;
jmp write;
write:
mov byte ptr [eax + ebx], cl
next_indx:
inc edi;
exit:
cmp edi, array_size;
jl readArray;
mov char_array, eax;
}
}
Explanation:
- Move char_array to eax as it is base image
.
- Use ebx as offset
.
- Use ecx as the storage register
.
- check if cl is <= than ASCII value 65 (A)
.
Answer:
Consider the following code.
Explanation:
save the following code in read_and_interp.m
function X = read_and_interp(s)
[m, n] = size(s);
X = zeros(m, 1);
for i = 1:m
if(str2num(s(i, 2:5)) == 9999)
% compute value based on previous and next entries in s array
% s(i, 2:5) retrieves columns 2-5 in ith row
X(i,1) = (str2num(s(i-1 ,2:5)) + str2num(s(i+1,2:5)))/2;
else
X(i,1) = str2num(s(i,2:5));
end
end
end
======================
Now you can use teh function as shown below
s = [ 'A' '0096' ; 'B' '0114' ; 'C' '9999' ; 'D' '0105' ; 'E' '0112' ];
read_and_interp(s)
output
ans =
96.000
114.000
109.500
105.000
112.000