在switch语句中将char转换为double

时间:2018-11-28 08:16:12

标签: c++ function

这个问题我很困惑。谁能启发我?

问题是:

  

编写一个函数,将字符字母等级转换为其数值等效形式。使用下面的评分系统。 A = 4.0 B = 3.0 C = 2.0 D = 1.0 F = 0.0

     

要获得满分,您的答案必须使用switch语句。如果函数接收的字符不是A,B,C,D,F,则返回值0.0。原型如下:

console.log('grids len : ' + this.grids.length);
console.log('labels len : '  + this.labels.length);

<RadListView [items]="availableServices" class="radlist-group"
                        swipeActions="true" (itemSwipeProgressStarted)="onSwipeCellStarted($event)"
                        (itemLoading)="onItemLoading($event)" backgroundColor="#26252A" style="height:100%">
                <ng-template tkListItemTemplate let-service="item">
                    <FlexboxLayout flexDirection="row" backgroundColor="#26252A">
                        <GridLayout class="item"
                                    [id]="service.name"
                                    #grid
                                    rows="*, *, 2*" columns="100, *, 10">
                            <StackLayout row="0" rowSpan="3" col="0" backgroundColor="rgba(0,0,0,0.3)" height="80" width="80" verticalAlignment="center" horizontalAlignment="center" borderRadius="5">
                                <Label class="detailLabels" [text]="hi"></Label>
                            </StackLayout>
                            <StackLayout row="0" col="1" rowSpan="2" backgroundColor="rgba(0,0,0,0.3)" height="24" width="40%" verticalAlignment="center" horizontalAlignment="left" borderRadius="5">
                                <Label class="detailLabels" [text]="service.minutes + ' minutes'"></Label>
                            </StackLayout>
                            <StackLayout row="2" col="1" backgroundColor="rgba(0,0,0,0.3)" height="40" width="100%" verticalAlignment="center" horizontalAlignment="left" borderRadius="5">
                                <Label class="detailLabels" [text]="service.name"></Label>
                            </StackLayout>
                        </GridLayout>
                    </FlexboxLayout>
                </ng-template>

                <GridLayout *tkListItemSwipeTemplate columns="*, auto">
                    <StackLayout id="delete-view" col="1"
                                 class="delete-view">
                        <Image #label src="res://check-mark" height="80" width="100" (tap)="add($event)"></Image>
                    </StackLayout>
                </GridLayout>

            </RadListView>

//这是我的编码

double gradeNum(char grade)
{ //your code here

1 个答案:

答案 0 :(得分:0)

switch语句应在函数“ gradeNum()”中。 首先,您应该使用特定的输入来调用上述函数。例如:

int main()
{
   ...
   double output = gradeNum('A');
   ...
}
double gradeNum(char grade)
{ 
   switch (grade)
   {
     case 'A':
       return 4.0;

    case 'B':
       return 3.0;

   ....

   }

}